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

Option "formConfig" can't be changed dynamically #76

Closed
Enrica-r opened this issue Jul 5, 2016 · 6 comments
Closed

Option "formConfig" can't be changed dynamically #76

Enrica-r opened this issue Jul 5, 2016 · 6 comments

Comments

@Enrica-r
Copy link

Enrica-r commented Jul 5, 2016

During init of activeForm 'formConfig' is read and CSS are calculated once. LabelSpan and Size is stored in private variables like _labelCss or _inputCss. ActiveField reads this values during layout built.

In my form I have smaller and larger fields and sometimes two or one in a single row. I looked for a possibility to override the labelSpan value. As I didn't find an option to change the labelSpan value by calling the field method. So I had the idea to change value in 'formConfig' like

$form->formConfig = array_merge($form->formConfig, ['labelSpan' => 7]);

then call the $form->field method and change 'formConfig' back. Unfortunately there is no change.

Methods like activeForm->getInputCss() should recreate the CSS part on the fly by using getFormLayoutStyle() instead of reading a private variable.

Or do you see another possibility?
Thank you.

@kartik-v
Copy link
Owner

kartik-v commented Jul 5, 2016

Form config is set at ActiveForm initialization in the init method.

In my opinion you must use FormGrid builder for such variation scenarios.

@Enrica-r
Copy link
Author

Enrica-r commented Jul 6, 2016

I know about the init method. Form builder has other disadvantages. I can't build my own widgets and integrate it. I prefer to design my own views manually.

The grid system of bootstrap divide the size of a column if i use nested grids. see example:
example screen

That's why 'yii/bootstrap/ActiveForm' resp. 'yii/bootstrap/ActiveField' builds the layout wrapper in the field class. Wrapping options can be defined on level form and level field. The field options have more priority. But I prefer your form classes because all other functionality is great.

Anyway I have to find a solution even if I have to override your classes.

@kartik-v kartik-v closed this as completed Jul 6, 2016
@kartik-v
Copy link
Owner

kartik-v commented Jul 6, 2016

Am open for an enhancement. You can submit your ideas or share a PR as well. Let know.

@kartik-v kartik-v reopened this Jul 6, 2016
@Enrica-r
Copy link
Author

Enrica-r commented Jul 8, 2016

Hi Kartik
As you proposed I have enhanced the code. I will do the PR next week. see Screen
example-screen-corrected

Short explanation: I moved the initialization of labelCss, inputCss and offsetCss (getFormLayoutStyle) from ActiveForm to ActiveField because CSS of a field is a property of a field and not a form. The form config can be a frame which inherits a standard setting.

Now the definition of 'labelSpan' and 'deviceSize' is settable in fieldConfig and 'formConfig'. Plus 'formConfig' can be changed between 'ActiveForm::begin' and 'ActiveForm::end. This gives the possibility to use the setting for a group of fields. For an individual field the call is:

<?= $form->field($model, 'attributeName', ['labelSpan' => 2, 'deviceSize' => 'sm'])

Further I have compared your widgets with 'yii/bootstrap/ActiveForm' resp. 'ActiveField'. Your widget has more functionalities and it's much better. The only advantage of them is the enhanced template with label- and input wrappers plus the option of 'horizontalCssClasses' which gives a complete control for individual grid classes. Example 'col-sm-3 hidden-xs'. see http://www.yiiframework.com/doc-2.0/yii-bootstrap-activeform.html and http://www.yiiframework.com/doc-2.0/yii-bootstrap-activefield.html
My idea is: I enhance the template like as original Yii widget and build a 'Yii widget' like compatibility in your widget combined with your 'labelSpan' and 'deviceSize'. If 'horizontalCssClasses' is set then the CSS generated by 'labelSpan' / 'deviceSize' will be overwritten. Shall I try this?

@kartik-v
Copy link
Owner

kartik-v commented Jul 8, 2016

Sure you can go ahead with the enh. I have some thoughts on where it may break a few functionality. Will update on how to overcome those.

@kartik-v
Copy link
Owner

kartik-v commented Jul 9, 2016

Some feedback:

  1. The existing configuration as defined in formConfig (e.g. labelSpan, deviceSize) can continue to exist to avoid breaking BC.
  2. The fieldConfig property can override the above configuration.
  3. Need to consider fix for ActiveForm::fieldConfig as closure #75 as well...

I suppose you have mentioned on the same lines (but just wished to add few cents). Also when you have a code, I can update over that.

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

No branches or pull requests

2 participants