Skip to content

Commit

Permalink
#7 impliment empty conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Pollock committed Apr 9, 2019
1 parent efc1a7e commit 4acbc96
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
6 changes: 3 additions & 3 deletions packages/forms/src/CalderaForm/state/applyRule.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ describe( 'Applying rules to conditional state', ()=> {
[submitButton.fieldId]: null
};

it.skip( "Disables an empty field", () => {
it( "Disables an empty field", () => {
let conditionalState = new ConditionalState(initialState);
conditionals.forEach(rule => {
applyRuleToState(rule, conditionalState)
Expand All @@ -227,10 +227,10 @@ describe( 'Applying rules to conditional state', ()=> {
expect( conditionalState.isFieldDisabled(textField.fieldId)).toBe(false);
});

it.skip( 'Disables both fields', () => {
it( 'Disables both fields', () => {
conditionals = [...conditionals, {
type: 'disable',
rule: createFieldRule('is', textField.fieldId, '' ),
rule: createFieldRule('empty', textField.fieldId, '' ),
fields: [
submitButton.fieldId
]
Expand Down
10 changes: 10 additions & 0 deletions packages/forms/src/CalderaForm/state/createFieldRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ export const createFieldRule = (testType,fieldId,testValue) => {
return values.toLowerCase().indexOf( testValue ) >= 0;

};
case 'empty':
return (fieldValues) => {
const value = findFieldValue(fieldId, fieldValues);

return (
null === value
|| '' === value
|| Array.isArray(value) && 0 === value.length
);
};

default:
return () => false;
Expand Down
4 changes: 0 additions & 4 deletions packages/forms/src/CalderaForm/state/createFieldRule.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,6 @@ describe('createFieldRule', () => {
expect(rule(fieldValues)).toBe(true);
});





test('Empty conditional returns FALSE for zero', () => {
const fieldValues = {
f2: 9,
Expand Down

0 comments on commit 4acbc96

Please sign in to comment.