APIs

Show:

The ModelForm listens to the element you provide and checks to see if any elements with a name attribute changes. It will then set the changed value in the model with the corresponding attribute. Also, if the model changes, it will update the html element with that changed attributes name. Yes this is somewhat blackmagic but it reduces the amount of code you have to write. This class also handles errors in the model and properly adds them to the view next to the displayed element.

HTML Attributes for models and model forms. If you choose not to use a template builder (not recommended) you can create your own template and use these attributes on elements so that the model form can act correctly with the view.
name: the actual input element (i.e textarea, selects, input, etc.)
data-model-attr-field: the container element for an attribute. Used for hiding an entire field or display a field in error.
data-model-attr-header: The element that labels an attribute. Currently displays the name of an attribute and if it's required
data-model-attr-error: The element that holds the error description
data-model-attr-input: The element that will contain the input elements, if you want the model form to build it for you. (not fully reliable yet)
data-model-attr-display: The element that only displays data

Refer to awa.mvc.Model and the attributeProps field to see how the ModelForm interacts with the Model you provide.

Constructor

awa.ui.ModelForm

(
  • options.model
  • options.el
)

Parameters:

  • options.model awa.mvc.Model

    model that the model form updates and manages

  • options.el Element

    Unlike other views, you must supply a pre-existing element to this view.

Methods

bindToModel

(
  • [model]
)
Undefined

Binds the view to a Model. will explain more later.

Parameters:

  • [model] awa.mvc.Model | Backbone.Model optional

    Model to bind to

Returns:

Undefined:

check

(
  • name
  • checked
)
awa.mvc.ModelForm

checks the given element with the name

Parameters:

  • name String

    element name

  • checked Boolean

    Check or uncheck

Returns:

awa.mvc.ModelForm:

this

destroy

() awa.mvc.View

clears out all widgets, grids, and events. Also removes and destroys children

Returns:

awa.mvc.View:

this

doChildrenLayouts

() Undefined

Needed for height fixing and other positioning changes

Returns:

Undefined:

doLayout

() Undefined

Needed for height fixing and other positioning changes

Returns:

Undefined:

focus

(
  • name
)
awa.mvc.ModelForm

calls jQuery.focus on the given element with the name

Parameters:

  • name String

    element name

Returns:

awa.mvc.ModelForm:

this

get

(
  • name
)
Mixed

return value from element

Parameters:

  • name String

    element name

Returns:

Mixed:

value

getAttrField

(
  • attr
)
awa.ui.ModelFormAttribute

Parameters:

  • attr String

    Attribute name

Returns:

awa.ui.ModelFormAttribute:

awa.ui.ModelFormAttribute associated with attribute

getAttrInput

(
  • attr
)
jQuery.selector

Parameters:

  • attr String

    Attribute name

Returns:

jQuery.selector:

Input selector

getWidget

() Array

get the view controlling a widget by it's selector

Returns:

Array:

widgets

onRendered

(
  • callback
  • context
)
Undefined

This is called only once in the lifetime of a view, if you bind to it before the view is rendered, the function will be called after triggerRendered is called.

Parameters:

  • callback Function

    Callback

  • context Object

    Defines scope of callback

Returns:

Undefined:

refresh

() awa.mvc.View

There is a habit of re-rendering entire views when it may not be necessary. Parent views can check the rendered flag and call refresh instead if the child view has already been rendered.

Returns:

awa.mvc.View:

this

reload

() awa.mvc.ModelForm

Call this when new elements are added/removed from the main element of the form.

Returns:

awa.mvc.ModelForm:

this

render

() Undefined

overrides backbone.view's render method. Sets the rendered property to rendered and renders any provided templates. This also binds any buttons in the view to it's action IF it has an actions attribute. The action attribute value should match the name of the function in the view class.

Returns:

Undefined:

requestChange

(
  • callback
)
Undefined

Parent views should check this before changing/swapping a view. Useful for views that are in edit mode that you want to do confirmation before leaving.

Parameters:

  • callback Function

    function to call when you have determined if the view can close or not. If it can close, return an object with property 'success' set to 1.

Returns:

Undefined:

requestClose

(
  • callback
)
Undefined

Parent views should check this before closing a view. Useful for views that are in edit mode that you want to do confirmation before closing.

Parameters:

  • callback Function

    function to call when you have determined if the view can close or not. If it can close, return an object with property 'success' set to 1.

Returns:

Undefined:

setElement

(
  • element
  • [delegate]
)
Undefined

Overidden setElement method applies the className to the new element the view is applied to. Also, if multiple views are passed in (what is returned from a jquery selector) it will be the top of the list.

Parameters:

  • element Jquery.Selector

    Jquery selector

  • [delegate] ? optional

    ?

Returns:

Undefined:

toggle

(
  • name
)
awa.mvc.ModelForm

calls jQuery.toggle on the given element with the name

Parameters:

  • name String

    element name

Returns:

awa.mvc.ModelForm:

this

triggerRendered

(
  • args
)
Undefined

The view should only call this once its completely rendered. This does not include refreshing views (i.e. grids changing pages). This also sets the view's rendered property to true.

Parameters:

  • args Object

    parameter to emit

Returns:

Undefined:

viewOptions

() Array

the constructor uses this function to determine which properties to pull out of the passed in options to directly attach to the view. All other options can be referenced from the view's options property

Returns:

Array:

Acceptable view options

Properties

__parent__

View

Parent view object

Default: undefined

className

Boolean | Function

when this view is rendered, it will create a new element with this class added. If the setElement method is used, this will append itself to the class attribute

Default: "awa-mvc-View"

closeOnReplace

Boolean

Mostly for views that contain multiple views. This allows a parent view to know that the view should be closed and destroyed when another view is swapped in.

Default: false

globalKeys

Object

used for the keymaster plugin. These will be scoped to the entire app.

Default: undefined

keys

Object

used for the keymaster plugin. These will be scoped to this view in the future.

Default: undefined

refreshOnReplace

Boolean

Mostly for views that contain multiple views. This allows a parent view to know that the view should be refreshed when this view is swapped back in.

Default: true

rendered

Boolean

Lets you know if this view object has been rendered or not. If you override the render method without doing a supercall, be sure to set it to true when you are done rendering.

Default: false

title

Strin

Can be used by parent views to put on tabs, control bars, popup headers, etc. Use accessor methods.

Default: "View"

tpl

Function

default template to use with this view, the render method will use this and inject the resulting html into it's $el.

Default: undefined

tplArgs

Object

arguments that are passed to the template

Default: undefined