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

Method update

src/View/Field.js:145–178  ·  view source on GitHub ↗

* Updates view on model change. * @return {FieldView} Fluent interface

()

Source from the content-addressed store, hash-verified

143 * @return {FieldView} Fluent interface
144 */
145 update () {
146 const $field = this.getElement()
147
148 // Set width attr
149 $field.dataset.width = this.getModel().getWidth()
150
151 // Set focus modifier
152 if (this.hasFocus()) {
153 $field.classList.add('field--focus')
154 } else {
155 $field.classList.remove('field--focus')
156 }
157
158 // Add invalid modifier
159 if (!this.getModel().isValid() || this.getMessage() !== null) {
160 $field.classList.add('field--invalid')
161 } else {
162 $field.classList.remove('field--invalid')
163 }
164
165 // Remove old message, if any
166 if (this._$message !== null && this._$message.parentNode !== null) {
167 this._$message.parentNode.removeChild(this._$message)
168 }
169 this._$message = null
170
171 // Create new message, if any
172 this._$message = this.renderMessage()
173 if (this._$message !== null) {
174 this.getElement().appendChild(this._$message)
175 }
176
177 return this
178 }
179
180 /**
181 * Triggered when view receives focus.

Callers 1

setMessageMethod · 0.95

Calls 7

getMessageMethod · 0.95
renderMessageMethod · 0.95
getElementMethod · 0.80
getWidthMethod · 0.80
hasFocusMethod · 0.80
getModelMethod · 0.45
isValidMethod · 0.45

Tested by

no test coverage detected