npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

modui-field

v1.2.7

Published

baseFieldView =============

Downloads

14

Readme

modui-field

modui-field is an abstract class that is extended to provide a consistent interface for getting, setting, and validating values of modui components. Imagine we have a form that contains name, age, and locationn fields. If all our fields extend modui-field, setting the values of the fields in the form is as easy as:

$( '.my-form' ).moduiField( 'set', {
	name : 'John Elliot',
	age : 33,
	location : {
		street : '23 Monkey Road'
		city : 'Ubud',
		state : 'Gianyar',
		country : 'Bali'
	}
} );

Field values can be any type. They can even be composed of smaller values that correspond to sub-fields, as is the "location" value in the above example. modui-field has built in support for sub-fields with getting, setting, and validating values.

Methods

Methods that generally do not need to be overridden by derived classes.

field.getValue( options )

Return the current value of the field. If immediate : true is in options, the value returned is pulled directly from the representation of the field's value that resides in the DOM (via field._pullValue()). The option can be used to pull the current value from a text field that is currently being edited.

field.setValue( newValue, options )

Set the current value of the field. If newValue is not the same as the current value, a change message is spawned using Backbone.Courier (unless slient : true is supplied in the options hash).

field.attemptSubmit()

// Documentation needs to be written

field._processValueChange()

This private method should be called internally whenever the representation of the field's value that resides in the DOM is potentially changed. For example, in the context of a text field, this method would be called on blur, since the representation of the fields value that resides in the DOM (that is, the string inside the input field) may have changed.

field._processValueChange() performs validation on the value in the DOM by calling field._coerceToValidValue(). If the value is valid or can be coerced to be valid, then field.setValue() is called with the new value. Otherwise, the representation of the field value in the DOM is reset to its last valid state.

Methods that generally should be overridden by derived classes

field._pullValue()

This private method should return the representation of the field's value that resides in the DOM. For example, a text field might return the value of the input element by calling this.$el.val(). The value returned does not need to be a valid value as it will always pass through field._coerceToValidValue() before being used.

field._pushValue( value )

The inverse of field.pullValue(), this method should push value to the representation of the field's value that resides in the DOM. For example, a text field might call this.$el.val( value ) to set the value of its input element. value is guaranteed to be a valid value since it will have passed through field._coerceToValidValue().

field._coerceToValidValue( sketchyValue )

This method transforms a potentially invalid value into a valid value. For example, an integer field might return Math.round( sketchyValue ) because its value can only be an integer. In the case that sketchyValue can not be transformed into a valid value, this method should return undefined.

field.getFormErrors()

This method should examine field.value and return an array of form errors. Form errors are those problems with the current value that should prevent a form that contains this field from being submitted. For example, a text field might an error object in the case that the current value exceeds its maxLength option. (Note it is not necessary to check for an invalid value, since field._coerceToValidValue() always protects the field from having an invalid value.)

field.showFormErrors( errors )

This method takes an array of form errors, as returned by field.getFormErrors(), and should manipulate the DOM to show visual cues that indicate to the end user those errors are present. For example, the default behavor is to toggle a has-form-errors class on the field element, which results in the color of the field being displayed in red.