Coder Social home page Coder Social logo

Comments (9)

kristijanhusak avatar kristijanhusak commented on July 22, 2024

There are 2 ways to handle this:
By passing custom template to the field like this:

<?php
class ChoiceForm extends Form {
    public fuction buildForm()
    {
        $this->add('choice_field', 'choice', [
            'choices' => [1 => 'choice_1' , 2 => 'choice_2'],
            'template' => 'fields.custom_choice',    // resources/views/fields/custom_choice.php
            'expanded' => true,
            'multiple' => true

And content of the custom_choice.php set to your needs, just make sure it has all functionality from the default ones (if checks, etc)

Another way is to publish views with php artisan vendor:publish, and change choice.php in resources/views/vendor/laravel-form-builder/choice.php.

Edit: You need to change checkbox.php, not choice.php.

from laravel-form-builder.

jaroslawziolkowski avatar jaroslawziolkowski commented on July 22, 2024

Your code block is empty :)

from laravel-form-builder.

kristijanhusak avatar kristijanhusak commented on July 22, 2024

Yea i pressed ctrl enter accidentally. Updated it.

from laravel-form-builder.

kristijanhusak avatar kristijanhusak commented on July 22, 2024

There is also one more way. In the view you can do this:

foreach ($form->choiceField->getChildren() as $child) {
    <div class="wrapper">
        {!! form_row($child) !!}
    </div>
}

If you are changing checkbox.php just remove check $options['is_child'] and it will work.

Hope i helped.

from laravel-form-builder.

kristijanhusak avatar kristijanhusak commented on July 22, 2024

Did you manage to set it up?

from laravel-form-builder.

jaroslawziolkowski avatar jaroslawziolkowski commented on July 22, 2024

It works.
I added to field config:

$form->add('name', 'choice',['optionWrapper'=>['type'=>'div','class'=>'classess-list'],'template'=>'fields.custom_choice','expanded'=>true,'multiple'=>true,'choices'=>$this->getoptions(),

and in resources/views/fields/custom_choice.php

<?php if ($showField): ?>
        <?php
        if(array_key_exists('optionWrapper',$options)){
            $wrapperStart = '<'.$options['optionWrapper']['type'].' class="'.$options['optionWrapper']['class'].'">';
            $wrapperEnd = '</'.$options['optionWrapper']['type'].'>';
        }else{
            $wrapperStart = null;
            $wrapperEnd = null;
        }
        foreach ((array)$options['children'] as $child): ?>

            <?=  $wrapperStart.$child->render().$wrapperEnd ?>
        <?php endforeach; ?>
    <?php endif; ?>

It's not perfect (not check exist class and not acces other attributes), but in my case very useful.
Thank you

from laravel-form-builder.

kristijanhusak avatar kristijanhusak commented on July 22, 2024

I will probably add an option to modify each choice field options separately, so it will be possible to add configuration like this. Will let you know when it's added so you can clean up your code.

from laravel-form-builder.

kristijanhusak avatar kristijanhusak commented on July 22, 2024

@jaroslawziolkowski
I added support for this. Check the docs here, bio and gender fields.
If you do not need wrapper at all, you can set it to false, for any field.
If you have choice with checkboxes or radios, you can set their options with choice_options like in gender field in the readme. Default for wrapper is false, because of BC.
When choice field generates select (expanded option is false), options are read from the main options, not choice_options.
Just do a composer update, and republish the views.

from laravel-form-builder.

jaroslawziolkowski avatar jaroslawziolkowski commented on July 22, 2024

@kristijanhusak
Great news, thank you :)

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.