• Determines which of the given options provided most closely matches the formData. Using getFirstMatchingOption() to match two schemas that differ only by the readOnly, default or const value of a field based on the formData and returns 0 when there is no match. Rather than passing in all the options at once to this utility, instead an array of valid option indexes is created by iterating over the list of options, call getFirstMatchingOptions with a list of one junk option and one good option, seeing if the good option is considered matched.

    Once the list of valid indexes is created, if there is only one valid index, just return it. Otherwise, if there are no valid indexes, then fill the valid indexes array with the indexes of all the options. Next, the index of the option with the highest score is determined by iterating over the list of valid options, calling calculateIndexScore() on each, comparing it against the current best score, and returning the index of the one that eventually has the best score.

    Adapted from https://github.com/rjsf-team/react-jsonschema-form/blob/b8f700a1cd2b9b8d7f67040e334836d236b325a4/packages/utils/src/schema/getClosestMatchingOption.ts#L136

    Parameters

    • rootSchema: JsonSchema

      The root JSON schema of the entire form (N.B. rootSchema can also be a piece of the actual root JSON schema, provided that has a JSON schema structure. Like for instance object type, or oneOf, and so on)

    • formData: any

      The form data associated with the schema

    • options: JsonSchema[]

      The list of options that can be selected from

    • Optional selectedOption: number = undefined

      The index of the currently selected option, defaulted to undefined if not specified

    Returns number | undefined

    • The index of the option that is the closest match to the formData or the selectedOption if no match

Generated using TypeDoc