surveyjs / survey-library

Free JavaScript form builder library with integration for React, Angular, Vue, jQuery, and Knockout.
https://surveyjs.io/form-library
MIT License
4.03k stars 787 forks source link

can onValueChanging support async code #3710

Open iaminvictus1993 opened 2 years ago

iaminvictus1993 commented 2 years ago

Are you requesting a feature, reporting a bug or asking a question?

question

What is the current behavior?

onValueChanging cant support async code

What is the expected behavior?

before change the question value, I want to popup a modal to confirm whether change the value

How would you reproduce the current behavior (if this is a bug)?

  // use window.confirm it works, this is my expect
  const onValueChanging = async (sender, options) => {
      if (!window.confirm('confirm change value') ) {
        options.value = options.oldValue;
      }
  }
// confirmChangeAnswer method is a  custom confirm modal  function that return a boolean promise, but  not work
  const onValueChanging = async (sender, options) => {
      if (!await confirmChangeAnswer() ) {
        options.value = options.oldValue;
      }
  }

any suggestion to me?

Provide the test code and the tested page URL (if applicable)

Tested page URL:

Test code

your_code_here

Specify your

andrewtelnov commented 2 years ago

@iaminvictus1993 Yes, it doesn't support async and it can't from UI point of view. You can use survey.onServerValidateQuestions event to validate question input on server.

Thank you, Andrew

iaminvictus1993 commented 2 years ago

@andrewte thanks for your quick reply, I check this demo in my scenario. it may not suit me. we want to give a confirm to some important questions. value change is decided by the user not by any code. it seem like a delete action, we need popup a confirm. so any suggestion to hack this?

andrewtelnov commented 2 years ago

@iaminvictus1993 Your scenario is not clear to me right now. Could you please explain it better.

Thank you, Andrew

iaminvictus1993 commented 2 years ago

thanks @andrewtelnov, all I want is before changing a question value, I want to show a confirm modal to cancel or accept the value change. this work fine demo can meet my scenario, except it's no ui confirm。 so I want to custom the window.confrim modal, I try this not work demo.

andrewtelnov commented 2 years ago

@iaminvictus1993 We can't lock UI onValueChanging. Here is your updated example.

Thank you, Andrew

iaminvictus1993 commented 2 years ago

@andrewtelnov thanks, I got your thoughts. but I still have some concerns about this.

  1. having dependent visibleif questions, this scenario will trigger customConfirm method several times, so this will open several confitm dialog .but I just want to popup only one confirm dialog no matter how many questions are related. here is the demo
  2. reset the value, the ui may be confusing. but this may be accepted