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.12k stars 802 forks source link

Function isValueEqual return false for equals arrays #7886

Closed FHourmy closed 6 months ago

FHourmy commented 7 months ago

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

Bug

What is the current behavior?

function isValueEqual returns false when comparing arrays

What is the expected behavior?

function isValueEqual should return true for arrays when elements are the same (or at least when reference is the same)

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

repro : https://codesandbox.io/s/pensive-babbage-nq43rr you can see in the console the comparison results when clicking a checkbox (see function added to onValueChanged)

Specify your

andrewtelnov commented 7 months ago

@FHourmy survey.isValueEqual is a private function that except one name (question name) and a value. You don't need to use it. You can use Helpers.isTwoValueEquals() function. It has value1 and value2 as two first parameters and 3 optional parameters:

    x: any,
    y: any,
    ignoreOrder: boolean = false,
    caseSensitive?: boolean,
    trimStrings? : boolean

The class is located in survey-core in your case you can use it as: Survey.Helpers.isTwoValueEquals([1, 2], [1, 2]);.

Thank you, Andrew SurveyJS Team