Sha256: 709cf7f11207bc2230f4de9b52bd9c6ae645896c10450eccb97f67fdadca1a0a
Contents?: true
Size: 957 Bytes
Versions: 71
Compression:
Stored size: 957 Bytes
Contents
var ArrayFields = new Class({ version: 0.1, // Implements: [Options, Events], initialize: function(_object, _options) { if ( ! _object) { return; } // this.setOptions(_options); var elem = _object; var template = elem.getElement('input').clone().erase('value'); var currentNr = 0; new Element('span.add_field', {text: '+'}) .inject(elem) .addEvent('click', function(e){ var newInput = template.clone(); var arrayI = newInput.get('name').match(/.+?\[(\d+)\].+/); if (arrayI && arrayI[1]) { currentNr += 1; newInput.set('name', newInput.get('name') .replace(/(.+?\[)\d+(\].+)/, '$1'+(parseInt(arrayI[1], 10)+currentNr)+'$2') ); } newInput.inject(e.target, 'before'); }); elem.getParent('form').addEvent('submit', function(){ elem.getElements('.array_fields').each(function(input){ if (input.value) { return; } input.erase('name'); }); return true; }); } });
Version data entries
71 entries across 71 versions & 1 rubygems