Last active
April 15, 2019 06:27
-
-
Save jessireedev/4dedabcb2bc33543a3a5a92fe7b6c845 to your computer and use it in GitHub Desktop.
repeaterVal2.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Developer: Jessiree de Vera | |
jquery.repeater repeaterVal() work-around support input type="number" | |
*/ | |
function repeaterVal2(repeaterSelector){ | |
// repeaterSelector is the same selector used in jquery repeater init | |
if($(repeaterSelector).length > 0){ | |
var values = {}; | |
var formValues = $(repeaterSelector).find("[name]"); | |
for(var i=0; i<formValues.length; i++){ | |
var $this = $(formValues[i]), name = $this.attr("name"), val = $this.val(); | |
var nameElements = name.split("["), formName = nameElements[0], formIndex = nameElements [1].slice(0, -1), formElementName = nameElements[2].slice(0, -1); | |
if($this.attr("type") === "checkbox"){ | |
val = $this.is(":checked"); | |
} | |
if(values.hasOwnProperty(formName) === false){ | |
values[formName] = {}; | |
} | |
if(values[formName].hasOwnProperty(formIndex) === false){ | |
values[formName][formIndex] = {}; | |
} | |
values[formName][formIndex][formElementName] = val; | |
} | |
return values; | |
} | |
else{ | |
return {}; | |
} | |
} | |
/* | |
Usage: | |
var values = repeaterVal2('.repeater'); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment