MCPcopy Create free account
hub / github.com/cryptii/cryptii / addField

Method addField

src/Form.js:77–108  ·  view source on GitHub ↗

* Adds a field to the form. * @param {Field|object} fieldOrSpec Field instance or spec object * @throws {Error} If field name is already assigned. * @return {Form} Fluent interface

(fieldOrSpec)

Source from the content-addressed store, hash-verified

75 * @return {Form} Fluent interface
76 */
77 addField (fieldOrSpec) {
78 // Retrieve field instance
79 let field = fieldOrSpec
80 if (!(fieldOrSpec instanceof Field)) {
81 // Resolve field spec to field instance
82 const spec = fieldOrSpec
83 if (spec.priority === undefined) {
84 // Use default priority
85 spec.priority = this._calculateDefaultPriority()
86 }
87 // Let the factory create an instance from given spec
88 field = this.getFieldFactory().create(spec)
89 }
90
91 // Verify that given field name is not already assigned
92 if (this.getField(field.getName())) {
93 throw new Error(
94 `Name '${field.getName()}' is already assigned to a field.`)
95 }
96
97 // Add field instance to the form
98 this._fields.push(field)
99 field.setDelegate(this)
100 this._sortFields()
101
102 // Add field subview
103 if (field.isVisible() && this.hasView()) {
104 this.getView().addSubview(field.getView())
105 }
106
107 return this
108 }
109
110 /**
111 * Returns named field value.

Callers 1

addSettingMethod · 0.80

Calls 11

getFieldFactoryMethod · 0.95
getFieldMethod · 0.95
_sortFieldsMethod · 0.95
hasViewMethod · 0.80
addSubviewMethod · 0.80
getViewMethod · 0.80
createMethod · 0.45
getNameMethod · 0.45
setDelegateMethod · 0.45
isVisibleMethod · 0.45

Tested by

no test coverage detected