UNPKG

files.com

Version:
60 lines (42 loc) 1.48 kB
/* eslint-disable no-unused-vars */ import Api from '../Api' import * as errors from '../Errors' import { getType, isArray, isInt, isObject, isString, } from '../utils' /* eslint-enable no-unused-vars */ /** * Class FormField */ class FormField { attributes = {} options = {} constructor(attributes = {}, options = {}) { Object.entries(attributes).forEach(([key, value]) => { const normalizedKey = key.replace('?', '') this.attributes[normalizedKey] = value Object.defineProperty(this, normalizedKey, { value, writable: false }) }) this.options = { ...options } } isLoaded = () => !!this.attributes.id // int64 # Form field id getId = () => this.attributes.id // string # Label to be displayed getLabel = () => this.attributes.label // boolean # Is this a required field? getRequired = () => this.attributes.required // string # Help text to be displayed getHelpText = () => this.attributes.help_text // string # Type of Field getFieldType = () => this.attributes.field_type // array(string) # Options to display for radio and dropdown getOptionsForSelect = () => this.attributes.options_for_select // string # Default option for radio and dropdown getDefaultOption = () => this.attributes.default_option // int64 # Form field set id getFormFieldSetId = () => this.attributes.form_field_set_id } export default FormField module.exports = FormField module.exports.default = FormField