Sha256: 972338e62549cfcc610f1f308113692978bb8583939364377e792ad9d0ef5b4e

Contents?: true

Size: 1.28 KB

Versions: 21

Compression:

Stored size: 1.28 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.plus_button.qe_button.default_form_align', {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('.plus_button'), 'before');
	}
});

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
bhf-1.0.0.beta16 app/assets/javascripts/bhf/classes/MultipleFields.js
bhf-1.0.0.beta15 app/assets/javascripts/bhf/classes/MultipleFields.js
bhf-1.0.0.beta14 app/assets/javascripts/bhf/classes/MultipleFields.js
bhf-1.0.0.beta13 app/assets/javascripts/bhf/classes/MultipleFields.js
bhf-1.0.0.beta12 app/assets/javascripts/bhf/classes/MultipleFields.js
bhf-1.0.0.beta11 app/assets/javascripts/bhf/classes/MultipleFields.js
bhf-1.0.0.beta10 app/assets/javascripts/bhf/classes/MultipleFields.js
bhf-1.0.0.beta9 app/assets/javascripts/bhf/classes/MultipleFields.js
bhf-1.0.0.beta8 app/assets/javascripts/bhf/classes/MultipleFields.js
bhf-1.0.0.beta7 app/assets/javascripts/bhf/classes/MultipleFields.js
bhf-1.0.0.beta6 app/assets/javascripts/bhf/classes/MultipleFields.js
bhf-1.0.0.beta5 app/assets/javascripts/bhf/classes/MultipleFields.js
bhf-1.0.0.beta4 app/assets/javascripts/bhf/classes/MultipleFields.js
bhf-1.0.0.beta3 app/assets/javascripts/bhf/classes/MultipleFields.js
bhf-1.0.0.beta2 app/assets/javascripts/bhf/classes/MultipleFields.js
bhf-1.0.0.beta1 app/assets/javascripts/bhf/classes/MultipleFields.js
bhf-0.10.17 app/assets/javascripts/bhf/classes/MultipleFields.js
bhf-0.10.16 app/assets/javascripts/bhf/classes/MultipleFields.js
bhf-0.10.15 app/assets/javascripts/bhf/classes/MultipleFields.js
bhf-0.10.14 app/assets/javascripts/bhf/classes/MultipleFields.js