Skip to content
This repository has been archived by the owner on Sep 24, 2018. It is now read-only.

ReferenceInput not triggering "waiting" state after first load even when matchingReferences not yet loaded #23

Open
python1981 opened this issue Jun 14, 2018 · 0 comments

Comments

@python1981
Copy link

When pre-populating a saved value, ReferenceInput getDataStatus() will only enter the "waiting" state when matchingReferences is not set.

But on the second load of a ReferenceInput it can never enter waiting state because matchingReferences is now set.

On the second load, if the new value to be pre-populated is not already in matchingReferences then the field SHOULD enter the waiting state until it is fetched, but it will not enter the waiting state so it renders prematurely.

Related code:

Existing code in ReferenceInput:getDataStatus()

waiting:
            (input.value && selectedReferenceError && !matchingReferences) ||
            (!input.value && !matchingReferences),

Suggested alternative:

waiting:
            (input.value && selectedReferenceError) ||
            (!input.value && !matchingReferences),

What you were expecting:
ReferenceInput+Autocomplete should always prepopulate with saved reference value and should be able to enter a waiting state even when some matchingReferences have been loaded if the input.value is not found in matchingReferences.

What happened instead:
Viewing a record with a saved value pre-populates correctly initially. Switching to another record of the same type will not pre-populate the value if the value is not coincidentally already in matchingReferences.

AutocompleteInput is particularly susceptible to this because often the loaded value will not already be present in matchingReferences.

Steps to reproduce:

  • Say we have a resource with a value controlled with ReferenceInput+AutocompleteInput.
  • Say there are two existing records:
    • Record 1 has value X
    • Record 2 has value Y
  • View Record 1 the value X pre-populates correctly into AutocompleteInput.
  • View Record 2 the value Y will not be found in matchingReferences so the field should enter the waiting state while the reference is fetched. Once fetched it should then pre-populate Y into AutocompleteInput.
  • However, when viewing Record 2 the value Y does not enter the waiting state, and does not pre-poulate and the dropdown shows the aor.input.references.single_missing error.

Environment

  • Admin-on-rest version: latest
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant