UNPKG

@progress/sitefinity-nextjs-sdk

Version:

Provides OOB widgets developed using the Next.js framework, which includes an abstraction layer for Sitefinity communication. Additionally, it offers an expanded API, typings, and tools for further development and integration.

56 lines (55 loc) 2.21 kB
import { FormRuleConstants } from '../form-rule-constants'; export class HideShowFieldFormRuleActionExecutor { actionName; constructor(actionName) { if (actionName === FormRuleConstants.Actions.Show || actionName === FormRuleConstants.Actions.Hide) { this.actionName = actionName; } else { throw new Error('Invalid action name! Only ' + FormRuleConstants.Actions.Show + ' and ' + FormRuleConstants.Actions.Hide + ' action names are allowed'); } } applyState(context, actionData) { let fieldIndex = context.helper.fieldIndexOf(context.fields, actionData.target); let fieldControlId = context.fields[fieldIndex].fieldControlId; if (context.fields[fieldIndex].visible) { context.helper.showField(context, fieldControlId); } else { context.helper.hideField(context, fieldControlId); } } ; updateState(context, actionData) { let updated = false; let fieldIndex = context.helper.fieldIndexOf(context.fields, actionData.target); if (this.actionName === FormRuleConstants.Actions.Show && !context.fields[fieldIndex].visible) { context.fields[fieldIndex].visible = true; updated = true; } else if (this.actionName === FormRuleConstants.Actions.Hide && context.fields[fieldIndex].visible) { context.fields[fieldIndex].visible = false; updated = true; } return updated; } ; undoUpdateState(context, actionData) { let fieldIndex = context.helper.fieldIndexOf(context.fields, actionData.target); if (this.actionName === FormRuleConstants.Actions.Show) { context.fields[fieldIndex].visible = false; } else { context.fields[fieldIndex].visible = true; } } ; isConflict(actionData, otherActionData) { return (otherActionData.name === FormRuleConstants.Actions.Show || otherActionData.name === FormRuleConstants.Actions.Hide) && actionData.target === otherActionData.target; } ; getActionFieldIds(actionData) { return [actionData.target]; } ; }