form2js
Javascript library for collecting form data
maxatwork/form2js @ GitHub
There is a addresses in my APP, there is a button that will add address if neccessary, but when I transfer the form to object and use ajax submit, the form object will only contain the last address. here is the demo
EDIT
this issue has been partial fixed, but we still think about if remove function is added, how we control the index of the list, if anyone has a good idea, you can give me a comment, thanks, and thank for the help from @weeksdev
Source: (StackOverflow)
I'm having login form with input fields being named as
<form id="loginForm" action="javascript:submitData(loginForm)">
<div class="col-md-12">
<label class="label" for="userName">Username</label>
<input type="text" id="userName" name="User.userName" placeholder="Username" />
</div>
<div class="col-md-12">
<label class="label" for="password">Password</label>
<input type="password" id="password" name="User.password" placeholder="Password" />
</div>
<div class="col-md-12">
<div class="g-recaptcha" data-sitekey="6LfQfAMTAAAAAM_5MWbC8ktOJPuOuXHfc3RMcPzx"></div>
</div>
<div style="padding-top: 10px;" class="col-lg-12 col-md-12 col-sm-12 col-xs-12" align="left">
<input type="submit" value="Sign In"/>
</div>
</form>
The purpose of name as User.*
is coz,
1) Form data will be converted to json, then to xml using form2js.js library
2) Then I'll convert the xml data into User object using JAXB at server side. User
is the root element of User object.
Since I can't specify a name to google Recaptcha's 'g-recaptcha-response' field, the xml formation is failed (final root element </User>
is not formed) due to the name="g-recaptcha-response"
instead of name="User.g-recaptcha-response"
in recaptcha. Even I don't like to play with recaptcha fields and also I dont want recaptcha value in my xml data, so is there any way to simply make form2js ignore a particular field ( name="g-recaptcha-response" in this case )? I'm attaching that recaptcha value in ajax request like
var gRecaptchaResponse = $("#recaptcha-response-field");
data: {
xmlData:xmlData,
gRecaptchaResponse: gRecaptchaResponse
}
So I've to simply ignore g-recaptcha-response
in form2js conversion. Is it possible?
Source: (StackOverflow)
I want to use form2js to convert a form's info to json to post. The problem is, the framework I am using uses require.js and it seems like I am not linking the form2js file with the requirejs config properly. I am getting an
Uncaught ReferenceError: form2js is not defined
error.
form2js is a function within the form2js.js file.
Here is the config file:
require.config({
baseUrl: "assets/js/lib/"
, shim: {
'backbone': {
deps: ['underscore', 'jquery'],
exports: 'Backbone'
},
'underscore': {
exports: '_'
},
'bootstrap': {
deps: ['jquery'],
exports: '$.fn.popover'
},
'form2js': {
exports: 'form2js'
}
}
, paths: {
app : ".."
, collections : "../collections"
, data : "../data"
, models : "../models"
, helper : "../helper"
, templates : "../templates"
, views : "../views"
}
});
require([ 'app/app'], function(app){
app.initialize();
});
And in the main html page I run this:
<script data-main="assets/js/main.js" src="assets/js/lib/require.js" ></script>
Any guidance to the right resources would be very appreciated!
Source: (StackOverflow)
Actually I am using form2js.js for converting my form data into JSON Object.
Here is the code:
var loginData = form2js('loginForm', '.', true);
console.log("FormData=" + JSON.stringify(loginData));
But the JSON String is empty. loginform is the ID of my form. I have searched for help on but I am not getting anything.
Here is the html form :
<form action="index.html" class="padder" id="loginForm" name="loginForm">
<label class="control-label">User</label>
<input id="userId" type="text" placeholder="User ID" class="form-control">
<input type="password" id="password" placeholder="Passcode" class="form-control">
<button type="submit" id="signInBtn" class="btn btn-info">Sign in</button>
</form>
Please help.
Source: (StackOverflow)