Fields.submit is not working. What am I doing wrong?

Fields.submit is not working. What am I doing wrong?

th3t1ckth3t1ck Posts: 228Questions: 37Answers: 1

I have a password field and a confirm password field. I am comparing the password fields and only want the password sent to the database not the repassword (Confirm Password). But I can't seem to get it to work. My code is as follows...

 $(document).ready(function() {
     editor = new $.fn.dataTable.Editor( {
         ajax: "users-con.php",
         table: "#users",
         fields: [ {
                 label: "Password:",
                 name: "oesa_users.password",
                 fieldInfo: "Password must be 8 charactors or more!",
                 type: "password",
             }, {
                 label: "Confirm Password:",
                 name: "repassword",
                 **submit: false,**
                 fieldInfo: "Type in the same password as above.",
                 type: "password",
             }
 ...

I also have an editor preSubmit like so...

        editor.on('preSubmit', function( e, data, action ){
        if(action === 'edit' || action === 'create' ){
          var password = this.field('oesa_users.password').val();
            var repassword = this.field('repassword').val();
            var password_length = this.field('oesa_users.password').val().length;
     //--- Compare Password and Confirm fields. ---//
       if ( ( password === repassword ) && (password >= 8) && ( password !== '' ) ) {
 //        alert('Encrypt the password');
                return true;
       }
     //--- Check if both fields match. ---//    
       else if ( password !== repassword ) {
                alert('Password and confirm password does not match!');
                return false;
       }
            //--- Check if password is blank. ---//    
       else if ( password === '' ) {
                alert('Password cannot be blank!');
                return false;
       }
                        //--- Check if password has enough charactors. ---//    
       else if ( password_length < 8 ) {
                alert('Password needs 8 charactors or more!');
                return false;
       }
        }
 })

Then it goes to the server side script to be posted. I thought I read that Fields.submit would allow or prevent the submission of the field but it is not working for me. I am still seeing it in the developer tools and editor throws an error because the repassword is not a field in the database...

data[row_9][oesa_users][password]: password
data[row_9][oesa_users][user_telephone]: 9168435555
data[row_9][oesa_users][permissions]: admin
data[row_9][oesa_users][status]: ACTIVE
data[row_9][oesa_users][last_verified]: 2018-12-03
**data[row_9][repassword]: password**

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    edited December 2018 Answer ✓

    What version of Editor are you using please? As you say, the fields.submit option should mean that the field isn't submitted to the server.

    Allan

  • th3t1ckth3t1ck Posts: 228Questions: 37Answers: 1

    Thank you for reply Alan. I'm using 1.7.4.

  • th3t1ckth3t1ck Posts: 228Questions: 37Answers: 1

    So I just read the release notes for 1.8.0 and it looks like that Fields.submit is not part of 1.7.4. Is that correct?

  • th3t1ckth3t1ck Posts: 228Questions: 37Answers: 1

    Well I just upgraded to 1.8.1 and it works. Thank you for pointing me in the right direction Allan.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    Yes you are exactly correct - the fields.submit option was added in 1.8. I had a typo in my link above, fixed now and it shows the version it was introduced in at the top right.

    Allan

  • th3t1ckth3t1ck Posts: 228Questions: 37Answers: 1

    Excelent. I totaly missed that "since version" when I read about the feature. I'm loving this package. I wrote my first app for the group I work in and they love it. Word got out and now I'm writing another one for a different group. Of course both groups do totaly different jobs. You're making me look good Allan :)

This discussion has been closed.