Skip to content
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

Only show field when another field value is true #527

Closed
baj84 opened this issue Mar 8, 2017 · 8 comments
Closed

Only show field when another field value is true #527

baj84 opened this issue Mar 8, 2017 · 8 comments

Comments

@baj84
Copy link

baj84 commented Mar 8, 2017

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!

@MarcosBL
Copy link
Contributor

MarcosBL commented Mar 9, 2017

There is a "toggle" field just for that, developed by @OwenMelbz in #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)

$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');

@baj84
Copy link
Author

baj84 commented Mar 9, 2017

That's perfect - thanks for your help

@oscarmlage
Copy link

oscarmlage commented Mar 20, 2017

+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!

@ghost
Copy link

ghost commented Jan 30, 2018

The 'default' setting not working. can someone verify?

@OwenMelbz
Copy link
Contributor

@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)

@ghost
Copy link

ghost commented Jan 30, 2018 via email

@OwenMelbz
Copy link
Contributor

@conandor that didnt work :)

@ghost
Copy link

ghost commented Jan 30, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants