confirmation Message on editor pre_submit

confirmation Message on editor pre_submit

eyal_hbeyal_hb Posts: 98Questions: 31Answers: 0

hey allan i want to used confirmation Message on pre_submit but i want to use sweetalert2
and not the confirm option, but i can make it work, the pre submit always make submit to form
here my code:

 editor.on('preSubmit', function (e, data, action) {
        if (action != "remove") {
            //editor.field('orderNumber').val()
            var IsUsed = false;
            var OrderNum = editor.field('orderNumber').val();
            var DayTripId = editor.field('DayTrip.DayTrip_Id').val();
            var data = table.data().toArray();
            data.forEach(function (row, i) {
                if (row.DayTrip.DayTrip_Id == DayTripId && row.Order_Num == OrderNum) {
                    return;
                }
                else if (row.Order_Num == OrderNum)
                {
                    IsUsed = true;
                    return false;
                }
            });
            if (IsUsed == true) {
                Swal.fire({
                    title: 'אזהרה!',
                    text: "מספר יום טיול קיים כבר במסלול,האם ברצונך להחליף ביניהם?",
                    icon: 'warning',
                    showCancelButton: true,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: 'כן, החלף!',
                    cancelButtonText: 'ביטול'
                }).then(function (result) {
                    if (result.value) {
                        return true;
                    }
                });
            }

        }
    });

Answers

  • allanallan Posts: 61,439Questions: 1Answers: 10,052 Site admin

    You need to return false from the function if you want Editor to not submit (like you are on line 15). It does not currently accept a Promise in return, so what you would need to do is something like:

    var allowedSubmit = false;
    
    editor.on('preSubmit', function (e, data, action) {
      if (action != "remove") {
        if (allowedSubmit) {
          return true;
        }
    
        ...
    
        Swal.fire({
          ...
        }).then(function (result) {
          if (result) {
            allowedSubmit = true;
            editor.submit();
            allowedSubmit = false;
          }
        });
      }
    });
    

    I've obviously shortened it a bit, but does that make sense?

    Allan

  • eyal_hbeyal_hb Posts: 98Questions: 31Answers: 0

    allan like this its still make submit and only after show message

    var allowedSubmit = false;
        editor.on('preSubmit', function (e, o, action) {
            if (action !== 'remove') {
                if (allowedSubmit) {
                    return true;
                }
                //var CountriesCount = this.field('Countries[].Country_Id').val();
                //var requireFlight = this.field('Trip.Requires_Flights').val();
                //// Only validate user input values - different values indicate that
                //// the end user has not entered a value
                    Swal.fire({
                        title: 'האם אתה בטוח שברצונך למחוק תמחיר?',
                        text: "לא יהיה ניתן לשחזר תמחיר זה!",
                        icon: 'warning',
                        showCancelButton: true,
                        confirmButtonColor: '#3085d6',
                        cancelButtonColor: '#d33',
                        confirmButtonText: 'כן, מחוק!',
                        cancelButtonText: 'ביטול'
                    }).then(function (result) {
                        if (result) {
                            allowedSubmit = true;
                            editor.submit();
                            allowedSubmit = false;
                        }
                    });
            }
        });
    
  • allanallan Posts: 61,439Questions: 1Answers: 10,052 Site admin

    Sorry - you should add return false; after the Swal.fire() call so the default action is cancelled.

    Allan

This discussion has been closed.