Question T17411
Visible to All Users

Widget Microphone with validations

created 10 months ago

I am using the microphone widget when I create my surveys, I would like to be able to have some validations on this type of question, such as the maximum time allowed in seconds of the recording or the maximum file size.
The "file" question type does have a property to validate the maximum size of the file, maxSize.
How could I do something like that? I'm using vue.
Thank you

Answers approved by surveyjs Support

created 10 months ago (modified 10 months ago)

Hi Luis,
If you are talking about the Microphone widget available with the surveyjs-widgets library, please note that the Microphone widget uses a third-party library (recordrtc).

If you wish to validate a user's input, you may wish to handle the survey.onValidateQuestion event. The Microphone question contains the recordingDuration property (measured in milliseconds). This property allows you to determine the duration of a recording.

JavaScript
survey.checkErrorsMode = "onValueChanged"; survey.onValidateQuestion.add((sender, options) => { if(options.question.getType() === "microphone" && options.question.recordingDuration > 5000) { options.error = "The recording should not exceed 5 seconds." } })

Consider the following demo: View Plunker.

Let me know if you have any further questions.

    Show previous comments (6)
    L L
    Luis Armando Rodriguez 10 months ago

      In the "runner" I cannot access the time property, in the json of the created survey I see that the time property has been saved correctly,

      Code
      { "type": "microphone", "name": "Pregunta_bd6a4d66", "title": { "es": "<p>Audio</p>\n" }, "time": "25000" }

      The code to access that property from the runner I use is:

      Code
      survey.getAllQuestions().forEach((question) => {   if (question.getType() === "microphone") {     console.log(question.name)     console.log(question.time)   } });
      Code
      survey.onValidateQuestion.add((sender, options) => {   if(options.question.getType() === "microphone") {            console.log(options.question.title)       console.log(options.question.time)        } })

        Hi Luis,
        In your survey runner component/webpage, please ensure that you called the Serializer.addProperty() function and registered the time property for your microphone widget.

        Let me know how it goes.

          You are always welcome. Please feel free to contact us if you require further assistance.