I am trying to exclude the disabled elements from the Json output. Can anyone help me.
Below is the code i am using. I have made the part in question bold.
My apologies if this seems like a retarded question.
/\**
\ Start Form to Json*
\/*
let isValidElement = element => {
return element.name && element.value;
};
let isEnabledElement = element => {
return (!(element.prop('disabled')));
};
let isValidValue = element => {
return (!['checkbox', 'radio'].includes(element.type) || element.checked)
};
let formToJson = elements => [].reduce.call(elements, (data, element) => {
if (isValidElement && isValidValue && isEnabledElement){
data[element.name] = element.value;
}
return data;
}, {});
let handleFormSubmit = event => {
event.preventDefault();
//call our function to get the form data
let data = formToJson(form.elements);
let dataString = document.getElementsByClassName('jsonObject')[0];
dataString.textContent = JSON.stringify(data, null, " ");
};
let form = document.getElementsByClassName('form_nostium')[0];
if (form){
form.addEventListener('submit', handleFormSubmit);
}
/\**
\ End Form to Json*
\/*
[link] [comments][Collection]webdev
No comments: