Sha256: f0317d2a3e8b2afc007716f6a06118597bd613ef19875131e5ff742a3e668b33

Contents?: true

Size: 1.24 KB

Versions: 92

Compression:

Stored size: 1.24 KB

Contents

var MultipleFields = new Class({
	version: 0.1,

	options: {
		spliter: ';'
	},

	// Implements: [Options, Events],

	initialize: function(_object, _options) {
		if ( ! _object) { return; }
		// this.setOptions(_options);
		if (_object.get('data-spliter')) {
			this.options.spliter = _object.get('data-spliter');
		}

 		var elem = _object;
		var template = elem.clone()
			.erase('name').erase('id').erase('data-spliter').erase('value')
			.addClass('template');

		elem.set('type', 'hidden');

		new Element('span.add_field', {text: '+'})
			.inject(elem, 'after')
			.addEvent('click', function(e){
				this.addField(elem, template);
			}.bind(this));

		elem.get('value').toString().split(this.options.spliter).each(function(data){
			this.addField(elem, template, data);
		}.bind(this));
	},
	
	addField: function(elem, template, data){
		template
			.clone()
			.set('value', data)
			.addEvent('change', function(e){
				var values = [];
				e.target.getParent('.input').getElements('.template').each(function(template){
					if (template.value.trim()) {
						values.push(template.value.trim());
					}
				});
				elem.set('value', values.join(this.options.spliter));
			}.bind(this))
			.inject(elem.getParent('.input').getElement('.add_field'), 'before');
	}
});

Version data entries

92 entries across 92 versions & 1 rubygems

Version Path
bhf-0.8.0 app/assets/javascripts/bhf/classes/MultipleFields.js
bhf-0.7.16 app/assets/javascripts/bhf/classes/MultipleFields.js
bhf-0.7.15 app/assets/javascripts/bhf/classes/MultipleFields.js
bhf-0.7.14 app/assets/javascripts/bhf/classes/MultipleFields.js
bhf-0.7.13 app/assets/javascripts/bhf/classes/MultipleFields.js
bhf-0.7.12 app/assets/javascripts/bhf/classes/MultipleFields.js
bhf-0.7.11 app/assets/javascripts/bhf/classes/MultipleFields.js
bhf-0.7.9 app/assets/javascripts/bhf/classes/MultipleFields.js
bhf-0.7.8 app/assets/javascripts/bhf/classes/MultipleFields.js
bhf-0.7.7 app/assets/javascripts/bhf/classes/MultipleFields.js
bhf-0.7.5 app/assets/javascripts/bhf/classes/MultipleFields.js
bhf-0.7.4 app/assets/javascripts/bhf/classes/MultipleFields.js
bhf-0.7.3 app/assets/javascripts/bhf/classes/MultipleFields.js
bhf-0.7.2 app/assets/javascripts/bhf/classes/MultipleFields.js
bhf-0.7.1 app/assets/javascripts/bhf/classes/MultipleFields.js
bhf-0.7.0.rc3 app/assets/javascripts/bhf/classes/MultipleFields.js
bhf-0.7.0.rc2 app/assets/javascripts/bhf/classes/MultipleFields.js
bhf-0.7.0.rc1 app/assets/javascripts/bhf/classes/MultipleFields.js
bhf-0.6.32 app/assets/javascripts/bhf/classes/MultipleFields.js
bhf-0.6.31 app/assets/javascripts/bhf/classes/MultipleFields.js