Comments (9)
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.
Your code block is empty :)
from laravel-form-builder.
Yea i pressed ctrl enter accidentally. Updated it.
from laravel-form-builder.
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.
Did you manage to set it up?
from laravel-form-builder.
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.
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.
@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.
@kristijanhusak
Great news, thank you :)
from laravel-form-builder.
Related Issues (20)
- v1.50 breaks field type collection HOT 5
- BUG: radio buttons chioce type returns an array HOT 5
- Feature request: Switching between classes by theme HOT 9
- Please change CHANGELOG and Releases HOT 3
- Select option for null values HOT 3
- Multiple file upload HOT 1
- Feature request: Add conditional field HOT 3
- Add Fieldset type HOT 3
- Compatibility Laravel 9 ? HOT 2
- getFieldValues() default value instead of null HOT 2
- Default placeholder for entity type(Field::ENTITY). HOT 1
- Radio button has problem HOT 2
- Using entity how we can display format with multiple columns HOT 1
- Collection of templated form HOT 2
- Error: count(): Argument #1 ($value) must be of type Countable|array, Mekongdelta\Slug\Models\Slug given HOT 5
- Validate without request HOT 10
- Invalid pattern for input
- At least one "choice" checkboxes required HOT 2
- Support for Laravel 11 HOT 4
- v1.53 - Method customLabel does not exist HOT 14
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-form-builder.