Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActiveField::staticControl inputOptions #168

Open
dicrtarasov opened this issue Jul 28, 2019 · 6 comments
Open

ActiveField::staticControl inputOptions #168

dicrtarasov opened this issue Jul 28, 2019 · 6 comments

Comments

@dicrtarasov
Copy link

Missing inputOptions in \yii\bootstrap4\ActiveField::staticControl

    public function staticControl($options = [])
    {
       +   $options = array_merge($this->inputOptions, $options);
        $this->adjustLabelFor($options);
        $this->parts['{input}'] = Html::activeStaticControl($this->model, $this->attribute, $options);
        return $this;
    }

Yii version - 2.0.23
yiisoft/yii2-bootstrap4 - 2.0.6

@yii-bot
Copy link

yii-bot commented Aug 6, 2019

Thanks for posting in our issue tracker.
In order to properly assist you, we need additional information:

  • When does the issue occur?
  • What do you see?
  • What was the expected result?
  • Can you supply us with a stacktrace? (optional)
  • Do you have exact code to reproduce it? Maybe a PHPUnit tests that fails? (optional)

Thanks!

This is an automated comment, triggered by adding the label status:need more info.

@dicrtarasov
Copy link
Author

dicrtarasov commented Aug 18, 2019

The ActiveField::staticControl method lost values of ActiveField::inputOptions.

This cause problem, for example we have an ActiveField:

$field = $form->field($model, $attribute, [
    'inputOptions' => ['class' => 'my-class']
]);

But when rendering it lost inputOptions:

echo $field->staticControl();

All other similar methods of \yii\widget\ActiveField has that behavior:

    public function input($type, $options = [])
    {
        $options = array_merge($this->inputOptions, $options);
    public function textInput($options = [])
    {
        $options = array_merge($this->inputOptions, $options);
    public function hiddenInput($options = [])
    {
        $options = array_merge($this->inputOptions, $options);
    public function passwordInput($options = [])
    {
        $options = array_merge($this->inputOptions, $options);
    public function fileInput($options = [])
    {
        if ($this->inputOptions !== ['class' => 'form-control']) {
            $options = array_merge($this->inputOptions, $options);
    public function textarea($options = [])
    {
        $options = array_merge($this->inputOptions, $options);

and so on ... So, staticControl() must not lost values, configured in inputOptions too. It's a bug.

@dicrtarasov
Copy link
Author

Similar issue for other methods:
yiisoft/yii2#17374

@samdark samdark transferred this issue from yiisoft/yii2 Aug 19, 2019
@simialbi
Copy link
Contributor

I don't think it makes sense to copy the general "input options" to static control too. It has other classes and properties:
https://getbootstrap.com/docs/4.3/components/forms/#readonly-plain-text

@dicrtarasov
Copy link
Author

dicrtarasov commented Aug 19, 2019

I don't think it makes sense to copy the general "input options" to static control too. It has other

For what other purposes and scenarios is this field intended and can be used? ActiveField renderer only by one of methods - textField or staticField or anothe. ActiveField instance not using many times with different input rendering. So, all it data intended to be used just for one purpose - rendering field. I'm usng ActiveField in my library and all workng fine except the staticControl, which, unlike other methods, loses and does not take into account the parameters. This is an obvious bug.

Other properties (like readonly="true") must be added to options by staticControl, as other method does.

@simialbi
Copy link
Contributor

simialbi commented Aug 20, 2019

No the static control is not like other fields. It's not just the readonly property, it has other classes and just exists in bootstrap library because it just exists in bootstrap framework. It makes no sense to copy all the options from default inputs and have to unset them in the staticControl method again...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants