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

Feature/Conditional Form #422

Merged
merged 25 commits into from Apr 24, 2018
Merged

Feature/Conditional Form #422

merged 25 commits into from Apr 24, 2018

Conversation

ibelar
Copy link
Contributor

@ibelar ibelar commented Mar 28, 2018

Conditional Form

Show or hide input field base on other input field condition.
Support all semantic-ui form validation rule.
Note on rule. FormService also add two more rule to semantic-ui existing ones:
notEmpty and isVisible.

  • Show "this field" if all condition are met.
    fieldRules is an array that contains items where each item describe the field to hide or show
    that depends on other field with their input value conditions.

Example

    $form->js()->atkConditionalForm(
      [ 'fieldRules =>
        [
          'fieldToShow' => ['field1' => 'notEmpty', 'field2' => 'number']
        ]
      ]);

Can be phrase this way: Display 'fieldToShow' if 'field1' is not empty AND field2 is a number.

Support for OR condition

Adding and array of field => rules for the same field will OR the condition for that field.

    $form->js()->atkConditionalForm(
      [ 'fieldRules =>
        [
          'hair_cut' => [
                          ['race' => 'contains[poodle]', 'age'=>'integer[0..5]'],
                          ['race' => 'isExactly[bichon]']
                        ]
       ]
      ]);

Can be phrase this way: Display 'hair_cut' if 'race' contains 'poodle' AND 'age' is between 0 and 5 OR 'race' contains the exact word 'bichon'.

Support AND condition on same field.

Adding an array of conditions for the same field is also support.

    $form->js()->atkConditionalForm(
      [ 'fieldRules =>
        [
          'ext' => ['phone' => ['number', 'minLength[7]']]
        ]
      ]);

Can be phrase this way: Display 'ext' if phone is a number AND phone has at least 7 char.

See semantic-ui validation rule for more details: https://semantic-ui.com/behaviors/form.html#validation-rules

Demos available using /demos/jscondform.php

Note

atkjs-ui.js need to be rebuild.

add support for radio button;
add new validation for number isEqual[number]
…ture/Conditoinal-Form

# Conflicts:
#	demos/jscondform.php
@codecov
Copy link

codecov bot commented Mar 29, 2018

Codecov Report

Merging #422 into develop will increase coverage by 0.64%.
The diff coverage is 90.47%.

Impacted file tree graph

@@              Coverage Diff              @@
##             develop     #422      +/-   ##
=============================================
+ Coverage      67.83%   68.48%   +0.64%     
- Complexity      1422     1428       +6     
=============================================
  Files             76       77       +1     
  Lines           3355     3376      +21     
=============================================
+ Hits            2276     2312      +36     
+ Misses          1079     1064      -15
Impacted Files Coverage Δ Complexity Δ
src/Form.php 64.6% <100%> (+3.06%) 50 <2> (+3) ⬆️
src/jsConditionalForm.php 83.33% <83.33%> (ø) 3 <3> (?)
src/jsExpression.php 84.61% <0%> (+1.28%) 36% <0%> (ø) ⬇️
src/TableColumn/Status.php 82.35% <0%> (+8.82%) 12% <0%> (ø) ⬇️
src/FormField/Radio.php 100% <0%> (+100%) 7% <0%> (ø) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5d8de30...519d58b. Read the comment docs.

@ibelar
Copy link
Contributor Author

ibelar commented Mar 29, 2018

Enhancement

Add ability to show or hide an entire group of fields by using a group selector.
To hide or show a group, simply add a field that belong to that group and pass the group selector.

$f->js(true)->atkConditionalForm([
   'fieldRules' => ['php' => [['dev' => 'checked']], 'other'=>['dev'=>'checked']],
   'selector' => '.atk-form-group']);

Show group where 'php' belong if dev is checked and show group where 'other' belong if dev is checked.

@romaninsh
Copy link
Member

probably needs a demo too.

@ibelar
Copy link
Contributor Author

ibelar commented Mar 30, 2018 via email

@ibelar ibelar removed the in progress label Apr 2, 2018
@romaninsh romaninsh self-requested a review April 2, 2018 22:21
Copy link
Member

@romaninsh romaninsh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR looks great. Reviewed.

Copy link
Member

@romaninsh romaninsh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However - documentation is lacking (.rst). I'll try to add it myself.

@romaninsh
Copy link
Member

romaninsh commented Apr 2, 2018

Additional problems:

  • Enter on the form is broken.
  • Form sometimes flickers (disappears then re-appears)
  • re-validation should occur when inputing, e.g. the first example should show next field not on change but before entry is finished

change type of event for validating input.
add debounce to package.
@romaninsh romaninsh merged commit b6e8afc into develop Apr 24, 2018
@romaninsh romaninsh deleted the feature/Conditoinal-Form branch April 24, 2018 14:15
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

Successfully merging this pull request may close these issues.

None yet

2 participants