I created magento admin grid form
In my form i am using checkbox app/code/[vendername]/[modulename]/Block/Adminhtml/Blog/Edit/Tab/Main.php
$fieldset->addField(
'applies_to_books',
'checkbox',
[
'label' => __('Applies to Books'),
'name' => 'applies_to_books',
'data-form-part' => $this->getData('applies_to_books'),
'onchange' => 'this.value = this.checked ? 1 : 0;',
]
);
$fieldset->addField(
'applies_to_levels',
'checkbox',
[
'label' => __('Applies to Levels'),
'name' => 'applies_to_levels',
'data-form-part' => $this->getData('applies_to_levels'),
'onchange' => 'this.value = this.checked ? 1 : 0;',
]
);
$fieldset->addField(
'applies_to_addons',
'checkbox',
[
'label' => __('Applies to Addons'),
'name' => 'applies_to_addons',
'data-form-part' => $this->getData('applies_to_addons'),
'onchange' => 'this.value = this.checked ? 1 : 0;',
]
);
While saving values are saved database but it not checked backend admin form enter image description here
1 Answer 1
You need to add one parameter 'checked' => true, in your code like below,
$fieldset->addField(
'applies_to_addons',
'checkbox',
[
'label' => __('Applies to Addons'),
'name' => 'applies_to_addons',
'data-form-part' => $this->getData('applies_to_addons'),
'onchange' => 'this.value = this.checked ? 1 : 0;',
'checked' => true //add this line in your each fieldset.
]
);
answered Nov 8, 2017 at 13:37
Vishwas Soni
1,56714 silver badges34 bronze badges
-
@mohan Welcome. I'm glad to help you. :)Vishwas Soni– Vishwas Soni2017年11月08日 13:48:09 +00:00Commented Nov 8, 2017 at 13:48
default