Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot clear Relationship field (without many set to true) #4711

Closed
chochihim opened this issue Jul 15, 2018 · 7 comments
Closed

Cannot clear Relationship field (without many set to true) #4711

chochihim opened this issue Jul 15, 2018 · 7 comments

Comments

@chochihim
Copy link

Expected behavior

For Relationship fields without many set to true, if I clear the Select input, the value should be removed.

Actual/Current behavior

The value remains.

This looks like caused by keystonejs/keystone@5df6846. The many: true case was fixed by keystonejs/keystone#4667. How about the many: false case?

Steps to reproduce the actual/current behavior

Environment

Software Version
Keystone v4.0.0-rc.1
Node.js 8.11.3
Browser Version 66.0.3359.139
@stennie stennie added the bug label Jul 15, 2018
@robinrossow
Copy link

I've also encountered this bug and looked a little into it. The POST request is already wrong (the data isn't erased) so this must be a frontend bug.
Unfortunately I don't know much about React so I wasn't able to find a solution :(

@stennie stennie added this to the 4.0.1 milestone Sep 9, 2018
@dfinton
Copy link

dfinton commented Sep 13, 2018

One item I'd like to add: I've seen this same issue, but the POST data is correct. I don't think it's a front-end issue, but when I look at the data in a pre-save hook the association ID is still set.

@robinrossow
Copy link

robinrossow commented Sep 13, 2018

@dfinton

frontend

post-data

Look at the Keyvisual field, it should be empty here but it isn't.

@dfinton
Copy link

dfinton commented Sep 13, 2018

Here are my screenshots: webkit form data with and without the relationship set. When the field is cleared, the data is no longer present between "state" and "author" (it's not anywhere else in the POST data either). I'm not sure if it has something to do with the fact our data includes a file upload which is why the form data is in this format, but it doesn't change the fact that on the server, it still thinks the relationship with that particular document exists.

insight-with-fund
insight-without-fund

@robinrossow
Copy link

Yeah I was wrong! I Looked at the server response instead of the actual POST request.

@Vultraz
Copy link
Contributor

Vultraz commented Feb 15, 2019

Just ran into this myself. I can't clear a singular relationship field (the value is restored when I save the document).

@mcglabs
Copy link

mcglabs commented Feb 16, 2019

The problem I found was with react-select and removing the single relationship, removed the hidden field that holds the value that is collated with the rest of the form data and sent to api. Because the param for the relationship is empty, the server process ignores any change. {many: true} works because a hidden field is generated in that case, see line 225: const emptyValueInput = ... in RelationshipField.js

My solution was to add:

{!this.state.value && !this.props.many && (
    <input type="hidden" name={inputName} value="" />
)}

in render beneath

{emptyValueInput}

on line 233

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants