$( window ).load( function( ) { $( "#dashboard-form" ).validate( { rules : { fullname : { required : true }, password : { required : true, minlength : 5, alphanumeric : true, nowhitespace : true }, email : { required : true, email : true } }, submitHandler : function( form ) { form.submit( ); }, focusCleanup : true, messages : { fullname : { required : "Por favor introduza o seu nome completo." }, password : { required : "Por favor introduza a sua nova palavra passe de utilizador.", minlength : "Por favor introduza uma palavra passe com no mínimo cinco caracteres.", alphanumeric : "Por favor introduza uma palavra passe utilizando apenas números ou letras.", nowhitespace : "Por favor introduza uma palavra passe sem espaços." }, email : { email : "Por favor introduza um email válido." } }, highlight : function( element ) { $( element ).closest( '.form-group' ).addClass( 'has-error' ); }, unhighlight : function( element ) { $( element ).closest( '.form-group' ).removeClass( 'has-error' ); }, errorElement : 'span', errorClass : 'help-block', errorPlacement : function( error, element ) { if( element.parent( '.input-group' ).length ) { error.insertAfter( element.parent( ) ); } else { error.insertAfter( element ); } } } ); $( "#telephone-group" ).click( function( ) { $( "#info-phone" ).attr( "title", "Insira o novo número de telefone de contacto do utilizador." ); $( "#telephone" ).removeAttr( "readonly" ); var value = $( "#hiddenfield" ).attr( "value" ).concat( ",telephone" ); $( "#hiddenfield" ).attr( "value", value ); } ); $( "#email-group" ).click( function( ) { $( "#info-email" ).attr( "title", "Insira o novo email do utilizador." ); $( "#email" ).removeAttr( "readonly" ); var value = $( "#hiddenfield" ).attr( "value" ).concat( ",email" ); $( "#hiddenfield" ).attr( "value", value ); } ); $( "#fullname-group" ).click( function( ) { $( "#info-fullname" ).attr( "title", "Insira o novo nome completo do utilizador." ); $( "#fullname" ).removeAttr( "readonly" ); var value = $( "#hiddenfield" ).attr( "value" ).concat( ",fullname" ); $( "#hiddenfield" ).attr( "value", value ); } ); $( "#password-group" ).click( function( ) { $( "#info-password" ).attr( "title", "Insira a nova palavra passe do utilizador, com no mínimo cinco caracteres e utilizando apenas números ou letras sem espaços." ); $( "#password" ).removeAttr( "readonly" ); var value = $( "#hiddenfield" ).attr( "value" ).concat( ",password" ); $( "#hiddenfield" ).attr( "value", value ); } ); $( "#telephone" ).change(function( ) { if( ( $( "#telephone" ).attr( "readonly" ) === undefined ) && ( $( "#submit-button" ).attr( "disabled" ) !== undefined ) ) { $( "#submit-button" ).removeAttr( "disabled" ); } } ); $( "#email" ).change( function( ) { if( ( $( "#email" ).attr( "readonly" ) === undefined ) && ( $( "#submit-button" ).attr( "disabled" ) !== undefined ) ) { $( "#submit-button" ).removeAttr( "disabled" ); } } ); $( "#fullname" ).change(function( ) { if( ( $( "#fullname" ).attr( "readonly" ) === undefined ) && ( $( "#submit-button" ).attr( "disabled" ) !== undefined ) ) { $( "#submit-button" ).removeAttr( "disabled" ); } } ); $( "#password" ).change(function( ) { if( ( $( "#password" ).attr( "readonly" ) === undefined ) && ( $( "#submit-button" ).attr( "disabled" ) !== undefined ) ) { $( "#submit-button" ).removeAttr( "disabled" ); } } ); } );