urlInput component
The urlInput component implements the <urlInput> form field.
Options
classMagento\Ui\Component\Form\Element\UrlInputcomponent.js file in terms of RequireJS.Magento_Ui/js/form/element/url-inputisDisplayAdditionalSettingstruesettingTemplateui/form/element/urlInput/settingsettingValuefalsetemplate.html template.ui/form/element/url-inputtypeSelectorTemplateui/form/element/urlInput/typeSelectorurlTypes{}Source files
Extends Abstract:
- app/code/Magento/Ui/view/base/web/js/form/element/url-input.js
- app/code/Magento/Ui/view/base/web/templates/form/element/urlInput/setting.html
- app/code/Magento/Ui/view/base/web/templates/form/element/urlInput/typeSelector.html
Examples
Configure component
By default, you can use Magento\Ui\Model\UrlInput\LinksConfigProvider, which provides text input for URLs. LinksConfigProvider is composite and you can add new options to the di.xml file.
<type name="Magento\Ui\Model\UrlInput\LinksConfigProvider">
<arguments>
<argument name="linksConfiguration" xsi:type="array">
<item name="default" xsi:type="string">Magento\Ui\Model\UrlInput\DefaultLink</item>
</argument>
</arguments>
</type>
The option class implements \Magento\Ui\Model\UrlInput\ConfigInterface and provides the child component configuration:
<?php
/**
* Copyright [first year code created] Adobe
* All Rights Reserved.
*/
declare(strict_types=1);
namespace Magento\Ui\Model\UrlInput;
class MyLink implements ConfigInterface
{
/**
* {@inheritdoc}
*/
public function getConfig()
{
return [
'label' => __('Select'),
'component' => 'Magento_Ui/js/form/element/select',
'template' => 'ui/form/element/select',
'sortOrder' => 10,
'options' => [
[
'value' => 1,
'label' => 'hello'
],
[
'value' => 2,
'label' => 'hello2'
]
],
'validation' => [
//'blacklist-url'=> //Add regexp to blacklist your URL here
//Add custom validation rule here
//validation.addRule
],
];
}
}
The application provides the ability to use two link types by default:
Magento\Catalog\Ui\Component\UrlInput\Categoryfor categoryMagento\Catalog\Ui\Component\UrlInput\Productfor product
Integration
This example integrates the urlInput component with the Form component.
<form>
...
<fieldset>
...
<urlInput name="url_input_example">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="urlTypes" xsi:type="object">Magento\Ui\Model\UrlInput\LinksConfigProvider</item>
</item>
</argument>
</urlInput>
</fieldset>
</form>
Result