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

FIX Handle validation errors in inline UploadFields #6091

Conversation

robbieaverill
Copy link
Contributor

I'm happy to discuss this approach - not sure if it's the "best" way to do it - the iframe and duplicated assets scared me off a little ;)

* Implemented redirect method to natively handle validation errors being sent back to the UploadField
* Resolves silverstripe#6086
@dhensby
Copy link
Contributor

dhensby commented Sep 27, 2016

Interesting, I take it there's no way to make this work without adding the redirect method?

We shouldn't really be putting new APIs in to the 3.4 branch...

@robbieaverill
Copy link
Contributor Author

@dhensby you guys would know better than me! This is the code that handled the form validation error and does something. I'm guessing that the UploadField might be a bit of a unique case in that it's run inside a frame. Looks like it's being treated as a controller, but doesn't share the same interface methods as a controller.

Agree re: adding methods to that branch - shall I change to 3 and rebase?

@robbieaverill robbieaverill changed the base branch from 3.4 to 3 September 28, 2016 23:26
@robbieaverill
Copy link
Contributor Author

Hey @dhensby - I've changed to the 3 branch instead. Nice to see that GitHub didn't make me rebase :)

@tractorcow
Copy link
Contributor

tractorcow commented Sep 29, 2016

@robbieaverill can I ask why is the method redirect() vs redirectBack()? I thought that this was the issue causing #6086. Even with the changed redirect option, it could fall back to redirectBack() in some cases.

If you are implement the redirect() method then it would pay to follow the same method signature as Controller::redirect, which redirects to the given parameter.

On a side note, this seems like another side effect of the framework having poorly defined roles for Controller vs RequestHandler. Form expects a Controller instance as parent, but there are MANY places we pass a RequestHandler instead, e.g. GridField.

@robbieaverill
Copy link
Contributor Author

robbieaverill commented Sep 29, 2016

Hey @tractorcow, I used redirect because is context seemed more relevant to the fact that the form is an embedded frame. The redirectBack behaviour would be the same if you didn't add the ->setRedirectToFormOnValidationError(true) flag.

I haven't done any edge case testing on this, just thought I would propose it since it does fix the immediate problem (like a band aid I suppose).

I know what you mean re the method signature, however it is not actually a redirect, so there is a semantic issue there which is more likely to be a problem in the way that class is architected or implemented. I don't want to go messing around with that of course. I didn't follow the method
signature because (A) it's not a controller, it's just pretending to be one to fit into the Form logic and (B) the destination argument has no use at all in its context. Since it doesn't inherit any kind of interface for the method I thought it could be treated more as a patch than anything. Figured it might be misleading to other developers if anything.

TL;DR: it's a quick fix for a bigger problem, one which I don't have time to look very far into I'm afraid.

I'm happy for you guys to do whatever you see fit with this PR, but the issue does exist even with a standard FormField with a validation rule, e.g. Max length as provided out of the box.

Cheers :-)

@tractorcow
Copy link
Contributor

tractorcow commented Nov 16, 2016

I had another think about it... and I'm wondering if we don't move some logic up from Controller into RequestHandler: redirect(), redirectBack(), and Link(). That way we can explicitly allow Form::setController() to take a request handler (which we do in many cases), rather than require a controller.

@robbieaverill
Copy link
Contributor Author

Yes please @tractorcow

@robbieaverill
Copy link
Contributor Author

Closing - not sure this is the best way to fix the problem for now.

@tractorcow
Copy link
Contributor

I've proposed this in #6362

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

Successfully merging this pull request may close these issues.

None yet

4 participants