Code Monkey home page Code Monkey logo

Comments (14)

kristijanhusak avatar kristijanhusak commented on August 23, 2024

When you pass the model, you have to manually assign choices:

<?php
    $this->add('fields', 'choice', [
        'choices' => $this->model->fields,
        ...
    ]);

from laravel-form-builder.

sitapraj avatar sitapraj commented on August 23, 2024

No,No,,,, how to populate the values that are saved for editing

from laravel-form-builder.

kristijanhusak avatar kristijanhusak commented on August 23, 2024

I don't understand your question. When the form is submitted, you should receive selected data in Input::get('fields'), and you handle them after.

from laravel-form-builder.

sitapraj avatar sitapraj commented on August 23, 2024

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

from laravel-form-builder.

kristijanhusak avatar kristijanhusak commented on August 23, 2024

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
    ]);

selected property holds the keys of all selected values, so if you have ['choice1 => 'some choice', 'choice2' => 'some other choice'], if you want them to both be selected you put:

<?php
'selected' => ['choice1', 'choice2']

from laravel-form-builder.

sitapraj avatar sitapraj commented on August 23, 2024

Thank You,,, what I need was this 'selected' => $this->model->fields

from laravel-form-builder.

kristijanhusak avatar kristijanhusak commented on August 23, 2024

Great. It should be automatic, but i think that works only when there is one selection.

from laravel-form-builder.

sitapraj avatar sitapraj commented on August 23, 2024

it works for multiple selection too...

from laravel-form-builder.

sitapraj avatar sitapraj commented on August 23, 2024

But, how this 'selected' => $this->model->fields can be use for subforms,,Subforms generate field name as name="subFormClassName[field]"????

from laravel-form-builder.

kristijanhusak avatar kristijanhusak commented on August 23, 2024

Same way, when you initialize it, pass model and use it.

from laravel-form-builder.

sitapraj avatar sitapraj commented on August 23, 2024

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".

from laravel-form-builder.

kristijanhusak avatar kristijanhusak commented on August 23, 2024

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])
    // ...
]);

from laravel-form-builder.

sitapraj avatar sitapraj commented on August 23, 2024

but passing value like this $model->subFormClassName[field] = "value" is not populating in the form

from laravel-form-builder.

kristijanhusak avatar kristijanhusak commented on August 23, 2024

yes, it's not working that way. It's not supported that way by laravel form builder class.

from laravel-form-builder.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.