View.Helpers

date_tag, file_tag, form_tag, form_tag_end, hidden_field_tag, get_data, img_tag, input_field_tag, link_data, link_to, link_to_if, password_field_tag, select_tag, submit_link_to, text_area_tag, text_field_tag, to_text

Prototype Methods

date_tag

date_tag(name, value , html_options) -> String

Creates a date tag.

- The name of the form element.
- Optional default date value.
- Optional html attributes.

file_tag

file_tag(name, value , html_options) -> String

Creates a file field that sets up the correct naming structure for JMVC file types.

- The name of the form element.
- Optional default value.
- Optional html attributes.

form_tag

form_tag(url_for_options, html_options) -> String

Creates a file field that sets up the correct naming structure for JMVC file types.

- Object used to direct to an action.
- Options used to create html attributes.

form_tag_end

form_tag_end() -> String

Outputs "</form>".

get_data

get_data(el) -> Object

Retrieves the data stored in the private hash for the passed element el. The key for the data is assumed to be located in the attribute _data, where it was placed by a call to link_data. Returns the data for the passed key, if found, or null. For example:

var recipe = MVC.View.Helpers.get_data(params.element);
- Element containing a _data attribute, which contains a key for data retrieval.

hidden_field_tag

form_tag_end(name, value, html_options) -> String

Creates a hidden field.

- The name of the form element.
- Optional default value.
- Optional html attributes.

img_tag

img_tag(image_location, options) -> String

Creates an image tage that loads from the resources/images folder.

- The name of the image.
- Optional html attributes.

input_field_tag

input_field_tag(name, value, html_options) -> String

Creates html input elements.

- The name of the form element.
- Optional default value.
- Optional html attributes.
link_data(store) -> String

Stores data passed in store in a private hash structure. Returns an attribute to place in an HTML element, which contains the key to retrieve the data. The attribute is something of the form _data='0', where 0 can be any integer. For example:

<tr class='recipe' <%=link_data(recipe)%>>
- Data somehow representing the element being created, which is to be stored for later retrieval.
link_to(name, url, html_options) -> String

Creates a link tag.

- HTML put between the a tags.
- Url for href attribute.
- Optional html attributes.
link_to_if(condition, name, url, html_options, block) -> String

Creates a link tag of the given name using the url if the condition evaluates to true. If the condition is false, only the name is returned.

- a contition to test if a link should be made.
- HTML put between the a tags.
- Url for href attribute.
- Optional html attributes.
- Optional block that is called if the condition is false.

password_field_tag

password_field_tag(name, value, html_options) -> String

Creates a password input element.

- The name of the form element.
- Optional default value.
- Optional html attributes.

select_tag

select_tag(name, value, choices, html_options) -> String

Creates a select field.

- The name of the form element.
- Optional default value.
- An array of choices. Each choice is an object with a name and value attribute. One choice can have a selected attribute.
- Optional html attributes.
submit_link_to(name, url, html_options) -> String

Creates a submit button that works like a hyperlink.

- Text to put in the submit link.
- Url for href attribute.
- Optional html attributes.

text_area_tag

text_area_tag(name, value, html_options) -> String

Creates a textarea.

- The name of the form element.
- Optional default value.
- Optional html attributes. It can take a special size attribute that takes a string like '30x5'. For example: text_area_tag('todos[description]',"Take out trash",{size: '30x5'})

text_field_tag

text_field_tag(name, value, html_options) -> String

Creates a standard text field.

- The name of the form element.
- Optional default value.
- Optional html attributes.

to_text

to_text(input, null_text) -> String

Creates human readable text using basic types.

- The javascript object to be converted to text.
- The string to display in case the input is null.