3

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>
Nikunj Vadariya
4,0371 gold badge21 silver badges30 bronze badges
asked Oct 25, 2016 at 13:12

1 Answer 1

2

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.

answered Oct 26, 2016 at 11:24
7
  • what about checkbox.? Commented Dec 8, 2017 at 9:35
  • smallint use for checkbox Commented Dec 8, 2017 at 9:47
  • till not saved checkbox value... Commented Dec 8, 2017 at 9:55
  • set length 6 to smallint Commented Dec 8, 2017 at 10:28
  • till not working.. May share my code with you ? Commented Dec 8, 2017 at 10:42

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.