Comments (5)
Sorry I don't get what you are trying to do here... What error are you trying to catch ? Form errors happen when the value submitted by the user are not valid but no errors are throw the errors are just added to the form. If the error came from outside the form it's a good idea to have an another props for the error outside the form.
from ux.
The Idea is that apart from FormErrors being added by Constraints, FormErrors would also be added manually by the Component.
For example, a User submits some data and this data - if valid from a constraint perspective - is then sent to a third party which validates it against some internal constraints and saves it. If this third party rejects the data, or an error occurs in transit, or while saving it, I would like the Form to reflect that by manually adding a FormError.
To expand on the example above:
#[LiveAction]
public function save(): ?Response
{
/** @var SomeModel $model */
$model = $this->getForm()->getData();
try {
$this->someService->save($model);
} catch (\Throwable $e) {
// Possible error cases would be:
// An error occurred during transit
// Third party server is not available
// manually add an error to the form which would then be rendered by the
// "form_errors(form)" twig function
$error = new FormError('An error occurred while saving your data');
$this->form->addError($error);
}
}
If this is currently not possible is it worth thinking about opening a feature request? Otherwise, the FormInterface::addError() function would be obsolete within LiveComponents.
from ux.
Ok now I got it now, thanks! You can't add Errors after your form have been submitted and validated. This not about LiveComponent, but more about how Symfony form works. So I think you have two options:
- You can create a custom constraint that do the check with your third party, and then add this custom constraint to your form (https://symfony.com/doc/current/validation/custom_constraint.html)
- You choose to validate your data after the form is submitted, but then you need to store the error message on a new propertie of your component and not on the form
from ux.
Yea I thought about these too, however they would still feel like a workaround, because even when adding the FormError to the form within the "instantiateForm()" function it is not rendered - and at this point the form is not submitted.
from ux.
Only errors related to validated field / models are kept (see: https://github.com/symfony/ux-live-component/blob/2.x/src/ComponentWithFormTrait.php), and the live props are the form values, not the form itself.
Not sure at all, but maybe you can call resetForm and then add some error ?
from ux.
Related Issues (20)
- [Translator] Warming up the cache fails when the translator is disabled. HOT 5
- [Dynamic Forms][Live Component] Rendering problem with data action and dependent field HOT 10
- [ChartJS] unable to configure tootlip label callback HOT 6
- [LiveComponent] Openning component in component ? HOT 1
- [Twig Components] - scoped props ? HOT 10
- [TwigComponent] Empty `props` throw incomprehensible Exception HOT 2
- Question regarding: Classically implemented embedded collection of forms inside a Live Component with ComponentWithFormTrait results in javascript console error "Invalid model name" after dynamically adding entries via javascript in the frontend. HOT 2
- `loading` attribute without Live Component HOT 3
- Impossible to use live components inside CollectionType HOT 1
- [TwigComponent][Doc] Remove false mention of PHP parsing
- Change another value of an entity using a LiveComponent HOT 4
- [LiveComponent] Error handling on Networking Errors HOT 3
- [Icons][Twig-Component] Update documentation for installation ux icons HOT 7
- [RFC][Translator] Possibility to change the location where the translations are created. HOT 2
- [Feature Request] Improved Anonymous Name Resolution HOT 12
- [Live component] Invalid cheksum exception with own hydrating methods after upgrade from 2.10 to 2.11 HOT 13
- [UX Autocomplete] setting "tom_select_options" overrides some default values set by ux which breaks plugin HOT 2
- Sharing Twig components HOT 10
- Deprecate the Lazy Image package HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ux.