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

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.
        ]
    );
  • @mohan Welcome. I'm glad to help you. :) – Vishwas Soni Nov 8 '17 at 13:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.