-
Notifications
You must be signed in to change notification settings - Fork 295
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
choices type field not populating value #29
Comments
When you pass the model, you have to manually assign choices: <?php
$this->add('fields', 'choice', [
'choices' => $this->model->fields,
...
]); |
No,No,,,, how to populate the values that are saved for editing |
I don't understand your question. When the form is submitted, you should receive selected data in |
ya.. I got that but in edit form how to populate selected values in 'choice' type using model.Means,if I want to pass default value as $model->id = 1,it displays in the form but $model->fields = ['choice1'], not displaying in the form,not showing selected choice,choice1 |
I'm not 100% sure, but i think that Laravel's form builder does not support automatically checking multiple values. You can try to put like this: <?php
$this->add('fields', 'choice', [
'choices' => $this->model->getAllPossibleFields(),
'selected' => $this->model->fields
]);
<?php
'selected' => ['choice1', 'choice2'] |
Thank You,,, what I need was this 'selected' => $this->model->fields |
Great. It should be automatic, but i think that works only when there is one selection. |
it works for multiple selection too... |
But, how this 'selected' => $this->model->fields can be use for subforms,,Subforms generate field name as name="subFormClassName[field]"???? |
Same way, when you initialize it, pass model and use it. |
if sub form attributes are the attributes of a model then how value can be populated. subFormClassName[field] is the attribute of model. $model->subFormClassName[field] = "value". |
I think just passing the model to the subform should work. <?php
$this->add('sub_form', 'form', [
'class' => \FormBuilder::create('Forms/SubForm', ['model' => $this->model])
// ...
]); |
but passing value like this $model->subFormClassName[field] = "value" is not populating in the form |
yes, it's not working that way. It's not supported that way by laravel form builder class. |
In $this->add('fields', 'choice', [
'choices' => ['choice1' => 'choice1', 'choice2' => 'choice2'],
'empty_value' => 'Select',
'multiple' => TRUE,
'attr' => ['class' => 'multiple-input'],
])
value is not populating through model,passing value as $model->fields = ['choice1']
$form = \FormBuilder::create('Form', [
'method' => 'PUT',
'url' => route('update', $id),
'model' => $model
]);
The text was updated successfully, but these errors were encountered: