1

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

asked Nov 8, 2017 at 13:24

1 Answer 1

3

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
1
  • @mohan Welcome. I'm glad to help you. :) Commented Nov 8, 2017 at 13:48

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.