Magento 2.1.2 – Category Custom Attribute Not Saving Value

adminhtmlcustom-attributesmagento-2.1

I am creating a custom attribute for categories using this resource.

The attribute field "Tagline – Category Head" is shown fine in the backend, but when I type a value and save the category, the value is not saved (it stays blank). I also searched the database for any field named "tagline" and nothing came up.

Here is the code

Setup/InstallData.php (just the install function)

public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
    /** @var EavSetup $eavSetup */
    $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);

    /**
     * Add attributes to the eav/attribute
     */

    $eavSetup->addAttribute(
    \Magento\Catalog\Model\Category::ENTITY, 'tagline1', 
        [
            'type' => 'text',
            'label' => 'Tagline - Category Head',
            'input' => 'text',
            'source' => '',
            'visible_on_front' => true,
            'required' => false,
            'sort_order' => 100,
            'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
            'group' => 'General Information',
        ]
    );
}

view/adminhtml/ui_component/category_form.xml

<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
      xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <fieldset name="taglines">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="label" xsi:type="string" translate="true">Taglines</item>
                <item name="collapsible" xsi:type="boolean">true</item>
                <item name="sortOrder" xsi:type="number">100</item>
            </item>
        </argument>
        <field name="tagline1">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="sortOrder" xsi:type="number">1</item>
                    <item name="dataType" xsi:type="string">string</item>
                    <item name="formElement" xsi:type="string">input</item>
                    <item name="label" xsi:type="string" translate="true">Tagline - Category Head</item>
                </item>
            </argument>
        </field>
    </fieldset>
</form>

Best Answer

Attribute type "Text" doesn't working as you need to change it as varchar.

You are not getting value in even database just because of it, check in eav_attribute as your attribute length is 0.