Skip to content

Commit

Permalink
[EAK-521] Ability to pass a path to set/set-if-blank actions to…
Browse files Browse the repository at this point in the history
… access nested fields
  • Loading branch information
ala-n committed May 15, 2024
1 parent bc18e28 commit e48f146
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 24 deletions.
13 changes: 11 additions & 2 deletions docs/content/dev-tools/depends-on/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,21 @@ order: 3

Built-in plug-in actions are:
* `visibility` - hide the element if the Query result is 'falsy'. <u>This is the default action that is applied when no action is specified.</u>

* `tab-visibility` - hide the tab or the element's parent tab if the Query result is 'falsy'
* `set` - set the Query result as the field's value (undefined Query result skipped)
* `set-if-blank` - set the Query result as the field's value only if the current value is blank (undefined Query result skipped)

* `set` - set the Query result as the field's value (`undefined` Query result skipped).
Supports optional `path` parameter to set the value to the nested property of the field.

* `set-if-blank` - set the Query result as the field's value only if the current value is blank (`undefined` Query result skipped).
Supports optional `path` parameter to set the value to the nested property of the field.

* `readonly` - set the readonly marker of the field from the Query result.

* `required` - set the required marker of the field from the Query result.

* `validate` - set the validation state of the field from the Query result.

* `disabled` - set the field's disabled state from the Query result. Supports multiple actions effect for the same field.

### Async actions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ js/accessors/dependsOnCoralFieldsetAccessor.js

# Actions
js/actions/dependsOnCoralBasicActions.js
js/actions/dependsOnCoralSetActions.js
js/actions/dependsOnCoralValidateAction.js
js/actions/dependsOnFetchAction.js
js/actions/dependsOnCoralTabAction.js
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,4 @@
ns.ActionRegistry.register('disabled', function setDisabled(state) {
ns.ElementAccessors.requestDisable(this.$el, state, this);
});

/**
* Set the field value from the query result, skip undefined query results
* query type: string
* */
ns.ActionRegistry.register('set', function setValue(value) {
if (value !== undefined) {
ns.ElementAccessors.setValue(this.$el, value);
}
});

/**
* Set the field value from the query result only if the field value is blank,
* skip undefined query results
* query type: string
* */
ns.ActionRegistry.register('set-if-blank', function setValueIfBlank(value) {
const current = ns.ElementAccessors.getValue(this.$el);
if ((current === '' || current === null || current === undefined) && value !== undefined) {
ns.ElementAccessors.setValue(this.$el, value);
}
});
})(Granite.$, Granite.DependsOnPlugin = (Granite.DependsOnPlugin || {}));

0 comments on commit e48f146

Please sign in to comment.