kartik-v / yii2-widget-activeform

Enhanced Yii2 active-form and active-field with full bootstrap styling support (sub repo split from yii2-widgets).
http://demos.krajee.com/widget-details/active-form
Other
64 stars 35 forks source link

disabled in ActiveField will always be overwritten, when diasabled is set in ActiveForm #139

Closed HagnMarkus closed 1 year ago

HagnMarkus commented 1 year ago

Version 1.6.3

When disabled is set (true or false) in ActiveForm it overwrites always disabled in ActiveField. So it is not possible to set a Field to disabled in an enabled Form.

Code in ActiveField:

/**
 * Parses the form flag (for disabled/readonly).
 *
 * @param  string  $flag
 * @param  array  $options
 * @return void
 */
protected function parseFormFlag($flag, &$options)
{
    if (!property_exists($this->form, $flag)) {
        return;
    }
    $action = $this->form->$flag;
    if ($action && is_callable($action)) {
        $options[$flag] = call_user_func_array($action, [$this->model, $this]);
    } else {
        $options[$flag] = $action;
    }
}

Code in 1.6.2

if ($this->form->disabled && !isset($options['disabled'])) {
    $options['disabled'] = true;
}
kartik-v commented 1 year ago

Have provided a fix. Kindly check and confirm if it resolves the issue and will tag a new release.

HagnMarkus commented 1 year ago

Now, when you set disabled = true for ActiveForm and disabled = false for ActiveField, it will enable the ActiveField in the disabled Form. Is this right and so wanted?

By the way: My problem is solved.

kartik-v commented 1 year ago

Now, when you set disabled = true for ActiveForm and disabled = false for ActiveField, it will enable the ActiveField in the disabled Form. Is this right and so wanted?

By the way: My problem is solved.

No - with this fix, if the ActiveField disabled or readonly option is set (whether true or false), it will override the ActiveForm setting. Can you confirm if this works as intended?

HagnMarkus commented 1 year ago

Yes, for me it is fine now!

But the question was in general: Does it make sense to have an active field in a disabled form? But this is more a matter of opinion. ;)

kartik-v commented 1 year ago

Yes, for me it is fine now!

But the question was in general: Does it make sense to have an active field in a disabled form? But this is more a matter of opinion. ;)

It can help developers to program dynamic flags for disabled or readonly based on their use case... like having only a checkbox enabled (at ActiveField) while all other fields are disabled (in form) - or vice versa.

HagnMarkus commented 1 year ago

Thanks! I think you can tag a new release.