When adding a new item, i'd like to only show input field 'X' when 'Y' has been selected.
Is this currently possible via the addField() method? Or would the only way be with my own custom javascript injected in?
Thanks!
There is a "toggle" field just for that, developed by @OwenMelbz in https://github.com/Laravel-Backpack/CRUD/pull/165 , but is not merged yet
I just copied the file proposed (as a custom template) in my own backpack space at resources/views/vendor/backpack/crud/fields/toggle.blade.php and started using it as per Owen instructions, worked great.
Usage: (angry is a boolean, why and what_can_we_do are varchar in my example)
````php
$this->crud->addField(
[
'label' => 'Are you angry?',
'name' => 'angry',
'type' => 'toggle',
'inline' => true,
'options' => [
0 => 'No',
1 => 'Si'
],
'hide_when' => [
0 => ['why', 'what_can_we_do'],
],
'default' => 0
]);
$this->crud->addField([ 'label' => "Why?", 'type' => 'text', 'name' => 'why', 'both');
$this->crud->addField([ 'label' => "What can we do?", 'type' => 'text', 'name' => 'what_can_we_do', 'both');
````
That's perfect - thanks for your help
+1 Worked here too, just keep in mind that if you're using iCheck you need to add some js in your document.ready (as @MarcosBL mentioned in #165, here) Thanks for sharing!
The 'default' setting not working. can someone verify?
@conandor been working for a while, so most likely a usage problem, can you share the code your using and show us the html its generated (not the whole document, just around the problem area)
The CRUD:

The HTML:

@conandor that didnt work :)
What method can I use to set the default choice.
Most helpful comment
There is a "toggle" field just for that, developed by @OwenMelbz in https://github.com/Laravel-Backpack/CRUD/pull/165 , but is not merged yet
I just copied the file proposed (as a custom template) in my own backpack space at resources/views/vendor/backpack/crud/fields/toggle.blade.php and started using it as per Owen instructions, worked great.
Usage: (angry is a boolean, why and what_can_we_do are varchar in my example)
````php
$this->crud->addField(
[
'label' => 'Are you angry?',
'name' => 'angry',
'type' => 'toggle',
'inline' => true,
'options' => [
0 => 'No',
1 => 'Si'
],
'hide_when' => [
0 => ['why', 'what_can_we_do'],
],
'default' => 0
]);
$this->crud->addField([ 'label' => "Why?", 'type' => 'text', 'name' => 'why', 'both');
$this->crud->addField([ 'label' => "What can we do?", 'type' => 'text', 'name' => 'what_can_we_do', 'both');
````