Skip to content
This repository

Made field instance available in template as variable #115

wants to merge 1 commit into from

4 participants

Corin Langosch Phil Freo Charles Davison Shane Reustle
Corin Langosch

I need to add a dynamic bootstrap add-on to one of my text inputs. As I didn't find a way on how to access "custom attributes" of the field from inside the templates I updated the code to also pass the field instance to the templates. Once can now do something like:

Inside the backbone view:

@model.someField = "lala"

Custom template:

  'field-with-addon': '
    <div class="control-group field-{{key}}">
      <label class="control-label" for="{{id}}">{{title}}</label>
      <div class="controls">
        <div class="input-append">
          {{editor}}<span class="add-on">{{field.model.someField}}</span>
        <div class="help-block">{{help}}</div>
Phil Freo

I was trying to do the exact same thing (for the exact same reason of bootstrap input add-ons)

Charles Davison

Would it make sense to pass in a data object instead of the field? If based on a model it would be the output from model.toJSON().

Charles Davison

If schema is also passed in then custom attributes on schema can be used too, just need to look out for conflicting variable names

Phil Freo

Rather than relying on model toJSON (sometimes which doesn't include every attribute if you don't want the server to see it) I'd rather put an extra options/values in the schema, and pass the schema. I'd want a schema attribute called addonAppend, or similar.

Originally I was thinking I wanted a reusable editor (which would always use a template) for bootstrap input add-on (input-prepend and input-append). Not sure if that makes more sense, or just a custom template.

Shane Reustle

I would agree that doing this in data would make more sense. Are we still still interested in pushing something like this in or can we close it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Aug 20, 2012
Corin Langosch Made field instance available in template as variable fed4fa6
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 1 addition and 0 deletions. Show diff stats Hide diff stats

  1. 1  src/field.js
1  src/field.js
@@ -79,6 +79,7 @@ Form.Field = (function() {
79 79
80 80
       //Create the element
81 81
       var $field = $(templates[schema.template]({
+        field: this,
82 83
         key: this.key,
83 84
         title: schema.title,
84 85

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.