-
Notifications
You must be signed in to change notification settings - Fork 217
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
Conditional form inputs based on checkbox or select #200
Comments
@7ammer can you make screen how do you see it |
Hi @Aios. Here you can see a conditional form. The user clicks the button and a form shows. Here are some syntax ideas: AdminFormElement::conditional(
AdminFormElement::checkbox('publish', 'Publish')->required()
)->equalTo('true',[
AdminFormElement:: date('from_date', 'From Date')->required(), // only required if condition is true
AdminFormElement:: date('to_date', 'To Date')->required() // only required if condition is true
]);
AdminFormElement::conditional(
AdminFormElement::select('status', 'Status', ['Unknown', 'Single', 'Married'])
)->equalTo('Single', [
AdminFormElement::text('name', 'Your Name')
])
->equalTo('Married', [
AdminFormElement::text('name', 'Your Name'),
AdminFormElement::text('name', 'Partners Name'),
AdminFormElement::file('file', 'Attach proof')
]); Alternatives: AdminFormElement::conditional(
AdminFormElement::checkbox('publish', 'Publish')->required(), [
'true' => [
AdminFormElement:: date('from_date', 'From Date')->required(), // only required if condition is true
AdminFormElement:: date('to_date', 'To Date')->required() // only required if condition is true
]
);
AdminFormElement::conditional(
AdminFormElement::select('status', 'Status', [
'Unknown',
'Single'
'Married'
]),
[
'Single' => [
AdminFormElement::text('name', 'Your Name')
],
'Married' => [
AdminFormElement::text('name', 'Your Name'),
AdminFormElement::text('name', 'Partners Name'),
AdminFormElement::file('file', 'Attach proof')
]
]
); AdminFormElement::checkbox('publish', 'Publish')->conditionalEquals(true, [
AdminFormElement:: date('from_date', 'From Date')->required(), // only required if condition is true
AdminFormElement:: date('to_date', 'To Date')->required() // only required if condition is true
]);
AdminFormElement::select('status', 'Status', [
'Unknown',
'Single'
'Married'
])->conditionalEquals('Single', [
AdminFormElement::text('name', 'Your Name')
])->conditionalEquals('Married', [
AdminFormElement::text('name', 'Your Name'),
AdminFormElement::text('name', 'Partners Name'),
AdminFormElement::file('file', 'Attach proof')
]) |
@7ammer Looks great!. What you think about survey.js? |
survey.js looks great and has a lot of features. Example using jquery-visibly.js: <form>
<select id="status">
<option value="Unknown">Unknown</option>
<option value="Single">Single</option>
<option value="Married">Married</option>
</select>
<div visibly="status:Single">
<input type="text" name="name">
</div>
<div visibly="status:Married">
<input type="text" name="name">
<input type="text" name="partner">
...
</div>
</form>
<script>
$(document).ready(function() {
$('[visibly]').Visibly();
})
</script> |
We need make some with advanced features but very simple & flexible - still looking for survey)) |
Just found this: http://www.celljs.org. Might be useful. |
@7ammer no - i think it will be as survey.js |
@Aios cool 👍 |
I think we’ll do it in a new branch. Though old Issue |
Such a functional will be in the next big update |
It would be great to have conditional input fields based on a checkbox's value or a select's value.
Form inputs could be simply shown/hidden with a bit of css (display:none / display:block).
The text was updated successfully, but these errors were encountered: