-
Notifications
You must be signed in to change notification settings - Fork 920
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
[4.2][Feature] Toggle Field Visibility #3753
Conversation
I was looking at Laravel-Backpack#165 by https://github.com/OwenMelbz and I wanted to update it to bring it into line with the current schema for Backpack. In the process, I realized all you need to do is add a few lines to the radio field. You can just add a parameter that this field can be a toggle. The rest of the usage is the same as in that PR. Additionally, one thing that bothered me is that you couldn't hide a field from two toggle fields. Now, I've added functionality that allows two toggle fields choose to hide another field, and then the only way it becomes visible if both toggles allow it to be visible *Usage* ``` //Controller->setUp() $this->crud->addField([ 'label' => 'Is this a featured article?', 'name' => 'featured', // can be a real db field, or unique name 'type' => 'toggle', 'options' => [ // same as radio, these act as the options, the key is the radio value 0 => 'Not Featured', 1 => 'Yes Featured' ], 'hide_when' => [ // these fields hide (by name) when the key matches the radio value 0 => ['featured_image', 'featured_title'], 1 => ['basic_title'] ], 'default' => 0 // which option to select by default ]); ```
The inspection completed: No new issues |
I love this, @zachweix . It's something people have requested FOR AGES and we haven't gotten to it because it's theoretically easy to do... but indeed... it's drag to have to do it every time. I have a few questions regarding this:
PS. I do NOT expect you've tested all of them 😅 Don't worry. I'm just asking. We'll need to do that before the merge though. |
|
I know that it's been forever since you sent this, but I tested this with: text,relationship,textarea,select_from_array,radio,date_range,custom_html (though that can be tricky),checkbox,time |
I like your suggestions in issue 4158, it's a lot to unpack, but to be honest I'm not able to read through the entire conversation from the last 9 days in there. I like that you want to make it more flexible so that it is more future proof. I guess if you don't think you'll be using this, you can close out the PR here |
I would imagine, yes 😅 Heads-up: I've created the JS library that will help us interact with fields. I think that will be a good starting point for us to merge first... then we can create a PHP syntax that uses the JS library. Not sure on the PHP syntax yet... but we might end up with something very similar to yours! After we're finished with the JS. Let's close this in favor of #4312 please... and build up from there. Again, thanks a lot for the PR. It's super-appreciated. It's a complicated matter, so a lot of PRs about this didn't get merged (including mine). Please don't let this discourage you from sending other PRs if you have ideas - they're super-welcome and it's how we grow and learn. Cheers! |
I was looking at #165 by https://github.com/OwenMelbz and I wanted to update it to bring it into line with the current schema for Backpack. In the process, I realized all you need to do is add a few lines to the radio field. You can just add a parameter that this field can be a toggle. The rest of the usage is the same as in that PR. Additionally, one thing that bothered me is that you couldn't hide a field from two toggle fields. Now, I've added functionality that allows two toggle fields choose to hide another field, and then the only way it becomes visible if both toggles allow it to be visible
Usage