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

Method setValue

src/Field.js:199–252  ·  view source on GitHub ↗

* Sets the value. Filters and validates value and updates the valid flag. * @param {mixed} rawValue Field value * @param {?object} [sender] Sender object. Only delegates that are not equal * to the sender will be notified. * @return {Field} Fluent interface

(rawValue, sender = null)

Source from the content-addressed store, hash-verified

197 * @return {Field} Fluent interface
198 */
199 setValue (rawValue, sender = null) {
200 // Validate value
201 const validationResult = this.validateValue(rawValue)
202 this._valid = validationResult === true
203
204 // Update message
205 if (!this._valid) {
206 if (typeof validationResult === 'object') {
207 this._message = validationResult.message
208 this._messageKey = validationResult.key
209 } else {
210 this._message = 'The value is invalid'
211 this._messageKey = 'invalid'
212 }
213 } else {
214 this._message = null
215 this._messageKey = null
216 }
217
218 // Update message on view
219 this.hasView() && this.getView().setMessage(this.getMessage())
220
221 if (!this._valid) {
222 this._value = rawValue
223 return this
224 }
225
226 // Filter value
227 const value = this.filterValue(rawValue)
228
229 // Check if value has changed
230 // Use the special comparison method when dealing with chain instances
231 const equal = value instanceof Chain
232 ? value.isEqualTo(this._value)
233 : this._value === value
234
235 if (!equal) {
236 this._value = value
237
238 // Update the value in view
239 if (this.hasView() && this.getView() !== sender) {
240 this.getView().updateValue()
241 }
242
243 // Notify delegate, if it is interested
244 if (this._delegate &&
245 this._delegate !== sender &&
246 this._delegate.fieldValueDidChange !== undefined) {
247 this.getDelegate().fieldValueDidChange(this, value)
248 }
249 }
250
251 return this
252 }
253
254 /**
255 * Revalidates the current value, sets {@link Field.isValid} flag to

Callers 6

revalidateValueMethod · 0.95
randomizeMethod · 0.95
extractMethod · 0.95
Field.jsFile · 0.45
Form.jsFile · 0.45
setFieldValueMethod · 0.45

Calls 10

validateValueMethod · 0.95
getMessageMethod · 0.95
filterValueMethod · 0.95
getDelegateMethod · 0.95
hasViewMethod · 0.80
setMessageMethod · 0.80
getViewMethod · 0.80
isEqualToMethod · 0.80
fieldValueDidChangeMethod · 0.80
updateValueMethod · 0.45

Tested by

no test coverage detected