0

I have custom module for admin where in block there is form. I want to set dynamic value to input type="text" but not able to set. Please, see my snippet below:

    $fieldset->addField(
                    'category_code', 'text', ['name' => 'category_code','value'=>'11', 'label' => __('Category Code'), 'title' => __('Category Code'), 'required' => true]
            );    
            }else{
            $fieldset->addField(
                    'category_code', 'text',['name' => 'category_code1', 
                          'value'=> $this->vendorAutoCode(),
                        'label' => __('Category Code'), 'title' => __('Category Code'), 'required' => true]
            );    
            }
public function vendorAutoCode(){
         //str_pad(rand(0,9999), 5, "0", STR_PAD_LEFT);
      return  str_pad(rand(0,9999), 5, "0", STR_PAD_LEFT);
    }
1
  • @Teja bhagavan Kollepara sir, Could you please guide me on same. Commented Aug 7, 2017 at 10:34

1 Answer 1

0

After digging in code solution like:

    if ($model->getId()) {
                $fieldset->addField('category_id', 'hidden', ['name' => 'category_id']);
                  $fieldset->addField(
                        'category_code', 'text', ['name' => 'category_code', 'label' => _('Category Code'), 'title' => _('Category Code'), 'required' => true])
                        ->setAfterElementHtml('<script>
                                document.getElementById("vendorcategory_category_code").setAttribute("disabled","disabled");

                                    </script>');
            }else{                  
                $fieldset->addField(
                        'category_code', 'text', ['name' => 'category_code', 'label' => _('Category Code'),'class' => 'category_code_disabled', 'title' => _('Category Code'), 'required' => true]);

                $model->setCategoryCode($this->vendorAutoCode());
            }
public function vendorAutoCode(){
        return str_pad(rand(0,9999), 5, "0", STR_PAD_LEFT); 
}

Your Answer

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.