New some help for sending a form
Dear All,
I would really appreciate to have a help on creating a form.
I have a jquerymobile application working with Phonegape.
When I test it from my prowser, it works fine, but there is a bug, when I run it on my iPhone.
After testing and searching, I notice that the bug come after I send my form.
I am using that form in order to save the profile.
I would like to know, if you can help me on createting a form validation. I have to field which must be validate in order to make sure, they are not empy.
Do you have a tuto?
For now I explain you how I did.
I ma using that plugin :
Validator
It a very good plugin.
On my profile page, I have that code
- $('#profile').live('pagebeforeshow', function(e){
// Get the values of the profile in order to have the field filled with the value, before
// modifying it
moduleId = localStorage.getItem('moduleId');
// Injection des valeurs du formulaire
modulesJSON = Modules.get('bipme');
for (var i = 0; i < modulesJSON['modules'].length; i++) {
if (modulesJSON['modules'][i].id == moduleId){
var moduleData = modulesJSON.modules[i];
};
};
//(I am using mustache in order to get the value)
// Get the Pseudo and fill the field
var tplFormPseudo = '{{pseudo}}';
var htmlFormPseudo = Mustache.to_html(tplFormPseudo, moduleData);
$('#profile #edit-profile #pseudo-edit').val(htmlFormPseudo).trigger('create');
/*
// Get the phone and fill the field
var tplFormGsm= '{{gsm}}';
var htmlFormGsm = Mustache.to_html(tplFormGsm, moduleData);
$('#profile #edit-profile #module-edit-gsm').val(htmlFormGsm).trigger('create');
*/
// Get the perimetre and ...
var tplFormPerimetre= '{{perimetre}}';
var htmlFormPerimetre = Mustache.to_html(tplFormPerimetre, moduleData);
$('#profile #edit-profile #module-edit-perimetre').val(htmlFormPerimetre).selectmenu('refresh');
// Get the profile Profile
var tplFormProfile = '{{profile}}';
var profile = Mustache.to_html(tplFormProfile, moduleData);
$('#profile #edit-profile').find( 'input[name="profile"]' ).attr('checked',false);
$('#profile #edit-profile #module-edit-'+profile).attr('checked',true);
$('#profile #edit-profile input[type="radio"]').checkboxradio('refresh');
// Get the Gsm country code
var tplFormGsmcc= '{{gsmcc}}';
var htmlFormGsmcc = Mustache.to_html(tplFormGsmcc, moduleData);
$('#profile #edit-profile #module-edit-gsmcc').val(htmlFormGsmcc).selectmenu('refresh');
// Get the Gsm aera code
var tplFormGsmac= '{{gsmac}}';
var htmlFormGsmac = Mustache.to_html(tplFormGsmac, moduleData);
$('#profile #edit-profile #module-edit-gsmac').val(htmlFormGsmac).selectmenu('refresh');
// Get the Gsm number
var tplFormGsmnb= '{{gsmnb}}';
var htmlFormGsmnb = Mustache.to_html(tplFormGsmnb, moduleData);
$('#profile #edit-profile #module-edit-gsmnb').val(htmlFormGsmnb).trigger('create');
// Get Mode
var tplFormMode = '{{mode}}';
var mode = Mustache.to_html(tplFormMode, moduleData);
$('#profile #edit-profile').find( 'input[name="mode"]' ).attr('checked',false);
$('#profile #edit-profile #module-edit-'+mode).attr('checked',true);
$('#profile #edit-profile input[type="radio"]').checkboxradio('refresh');
// When we click on save the validator plugin get in action
$("#edit-profile").validationEngine('attach',{
onValidationComplete : function(form, status){
// If there is no error
if(status == true){
// I update ma localStorage
// Get the new value of mode
for (var j = 0 ; j < form[0].mode.length; j++){
if(form[0].mode[j].checked == true){
var mode = form[0].mode[j].value;
}
}
// Get the new value of profile
for (var j = 0 ; j < form[0].profile.length; j++){
if(form[0].profile[j].checked == true){
var profile = form[0].profile[j].value;
}
}
// This is code which allow me to attribue a color to the marker profile.
var profileActual = Modules.getOneValue('modules','profile');
if (profileActual == profile){
var color = Modules.getOneValue('modules','iconColor');
}else{
var color = IconColor.selectAColor(profile);
}
// Save the value
Modules.edit('pseudo',form[0].pseudo.value);
Modules.edit('perimetre',form[0].perimetre.value);
Modules.edit('gsmcc',form[0].gsmcc.value);
Modules.edit('gsmac',form[0].gsmac.value);
Modules.edit('gsmnb',form[0].gsmnb.value);
Modules.edit('mode',mode);
Modules.edit('profile',profile);
Modules.edit('iconColor',color);
$.mobile.changePage('#modules', {
transition : 'slide'
//dataUrl : '#modules'
});
};
}
});
})
I am Ok to change my way to save my data, but I would like to know what you can suggest me.
Many thank for your ehlp