I'm diving into Angular4 forms validation. I was wondering if there is any library that introduce validation of controls in a template driven form.
What I'm looking for is a library that insert automatically the "Required." text field for every form element tagged as required, and so on for the other standard html5 validation attributes.
There are several good libraries for form validation available,
for example Angular2 Form Utils. It's pretty popular and powerful, and it also assists with error handling.
If this isn't what your looking for, npm has several others
Related
I was browsing the typo3 core Forms framework documentation but with no relevant answer to my requirements which are:
The form has to be displayed in a frontend overlay.
The filling process involves multiple steps where the user would be able to go back and forth.
The form fields must still be editable by a redactor.
I'm not sure about how the form framework behaves, so far I remember I think that multiple steps are configurable from the backend module but I don't know if it sends request to the controller after each step or if it sends everything only on submit.
I have an idea about how to implement it though, it's based on this question how to get a typo3 form framework html via ajax. Which would just let me provide the whole html content to the frontender and let him split the whole form into steps. The separation would be based on the addition of some special tags via the editor that would surround the fields you want in each step.
What do you think about that approach?
The form framework proceeds each form step seperately. So without developing your own form runtime, you have to keep proceeding every step seperate.
I see two possibilities:
1. Send each form step from frontend to the form controller and replace the response (html form) in the frontend.
That is the fast and easy way, as you use the existing form runtime.
Prepare a page which returns the rendered form as html
Fetch this page by JavaScript
Send the form data back to the given form action
The form controller proceeds the form with all its validators, rules and finishers and returns the next step, previous step, the current step with existing errors or the finishers response on success
Replace your form in the frontend with the already rendered html response of the form framework
The advantage of this way: Less effort and you can rely on the already existing validators, as you get an already validated response.
The disadvantage of this way --> it is more difficult to implement frontend validation, as you have a mix between frontend and server side validation.
2. Make the form framework kind of headless and work json based
In my opinion the better approach, but with a lot more effort to take.
You have to extend / overwrite the controller and the form runtime. This allows you more flexibility in handling the form by JavaScript and e.g. return the errors in a json object. It makes life easier when you want the form render and handle with a JS framework like react or vue.
To your question:
What do you think about that approach?
If I got it right, you want to keep ONE form step in the backend, but let the editor divide this form step into multiple steps by adding tags? You can try, but I don't see any real advantage in keeping the original form steps and proceed every step by sending the step to the controller and handle the response (like mentioned in 1.)
Summary:
In the past, I was thinking a lot about handling forms by JavaScript and came to the conclusion:
Keep the form framework's behaviour completely untouched with server side processing or make it frontend driven, with an own runtime. All mixtures between client and server side rendering will sooner or later run into bigger problems or at least a high effort. The form framework is pretty complex with a lot of possibilities, hook driven behaviour, etc. From my experience, you have to know it pretty good to develop without loosing control. In smaller projects with just one or two basic forms, I would try to avoid special cases with lots of JS. In bigger projects (with more budget), I would definitely go with my second mentioned approach (currently, I'm developing vue.js based rendering and handling of the form frontend). But these are just my five cents...
I am trying to find out what is the best approach for my task:
Create a form with validation, spamcheck etc. using existing functionality. The results of the form must be handled in an extension and sent to an external application via REST api. Additionally, an email should be sent.
I am still struggling with TYPO3 and would like some help for what might be a good approach. I would like to use existing functionality as much as possible and not reinvent the wheel.
there is the ext:form framework. I saw that there are finishers, but not that it might be possible to send the results of the form to a Controller action
if that is not possible, is it possible for my extension to get notified (e.g. signal / slot) when a form has been submitted
alternatively, I could use Fluid form ViewHelpers. I did not find much information about how to handle the validation
form.validationResults : I don't exactly understand what it does.
handle validation via JavaScript
Any pointers are appreciated.
as the title says, I'm trying to use a template-driven Angular form for providing the user a way to sign up and login. I've read a lot about the disadvantages of using template-driven forms when complex validation is required. However, this is not the case here. My question is: are there other disadvantages (that are not instantly evident or that may appear later) in using template-driven forms for such functionality when one usually starts with a clean form and submits data once really?
I've only been working with Angular (as opposed to AngularJS) for a couple of months, but for your simple scenario, I think that a Template-driven form is preferred.
You only need one-way data-binding, and you presumably only have two (or only a small handful of) entry fields, with simple validation requirements (do you need more than "required"?).
I think that Reactive Forms would be overkill here.
(If this is not the right place to post this kind of question I'd happily post it somewhere else)
I'm trying to build an interactive web application to manage company resources.
I have experience with Symfony2 but I kind of hit a wall with this new application.
I'd like to make this application quite interactive on the client side. Almost a full single webpage application.
My previous web applications would normally just use a typical MVC pattern with CRUD pages.
In those simple applications I would have
/employees/
/employees/create
/employees/detail/45
/employees/update/45
/employees/delete/45
Using symfony in this kind of application would give me a lot of advantages:
Routing
Security (CSRF tokens)
FormTypes and Form handling
Validation
Integration with Doctrine
Twig
Especially functionality like this in Twig was very refreshing (since my models were build as Doctrine entities):
<p>{{ employee.getCurrentTask().description }}</p>
The problem I'm facing now is that I feel like Symfony2 isn't really build for single webpage applications. As soon as I try to add some Ajax functionality I'm faced with these problems:
CSRF tokens invalid
Too much non reusable view/presentation logic in jQuery
Adding data-attributes in html to get id's etc...
I then looked into Knockout.js and Angularjs but then I feel like lose all of the advantages of Doctrine and Twig. I have to rebuild my models on the client side anyway and have to maintain them in two different locations then.
So I came up with this idea:
Use Symfony2 models and controllers to persist data to the database but let controllers in symfony just send out JSON and receive JSON (FOSRestBundle maybe?)
Use a framework like AngularJS or KnockoutJS to rebuild that JSON data on the client side to use 2-way binding.
But then how would I tackle the issues like Doctrine2 Relationships, Form Validation, CSRF which Symfony already solved but are unusable if I use a frontend js framework?
All suggestions are welcome!
Some words about JSON, Serialization and Models
Simon, I faced exactly the same questions and problems. First like ken already mentioned. You don't need to rebuild any model. Better use FosRestBundle and/or JMS Serializer. It turns you entities with relations into JSON objects. This objects are transferred via api to your frontend and you can work with them just like in twig, when you use angular.js like this
{[{ user.username }]}
is as same as in twig. But remember that you have to set custom brackets for angular because by default it uses the same as twig.
Routing
You talk of a single page application, so symfony's routing is kept on a low level to have few page refresh. Instead you have to use routing of your frontend framework, because I am only familiar with angular.js, I give an angular example:
app.config(function($routeProvider, $interpolateProvider) {
//here you go, custom brackets
$interpolateProvider.startSymbol('{[{');
$interpolateProvider.endSymbol('}]}');
$routeProvider.when('/user', {
controller: UserController,
templateUrl: Routing.generate('suser_list')
}).when('/ticket', {
controller: TicketController,
templateUrl: Routing.generate('ticket_list')
});
});
When you hit a link like
Go to tickets
AngularJs will know which frontend controller to trigger. Pretty great stuff, without page reload. Also have a look at FosJSRoutingBundle. It allows you to generate symfony routes in javascript, I use them to link js controllers with html templates where data is pushed in.
FormTypes, Form handling, Validation
Well, when you use a frontend framework like angularjs, your symfony form types are pretty useless. But I am not sure. Remember data is pushed and pulled via api as json, I think this would be a hard job for form types to handle this kind of compexity.
For validation you can use angular's live validation or have you symfony's validation in the backend, no problem. It might be a good thing to use both, client and server side validation.
Twig
Twig is out of the race. All data is rendered on the client side, and not pre rendered on server side like with twig. But that is only the case if your application is really a single page application. Of course you can use twig, but it will only refresh if you reload the entire page.
Integration with Doctrine
You can still use doctrine in the backend. Do you have a specific question regarding doctrine and SPA?
You don't need to rebuild the model in client. I normally just create a service in angularjs that provides json data. Data manipulation still happens server side using ajax.
For forms that requires csrf, I normally just send the html rendered by twig via json. Or you can serialize $form->createView() with jms serializer. However you will need some client script to transform the json data to actual form controls.
Is there a way (using JQuery or Java Script) to force an MVC2 form to perform validation on it's fields with Data Annotation validation without posting back to the server?
I have a MVC2 form that is quite complex. Many of the fields are hidden or displayed depending on other selections. Given this, some of the fields are validated using Data Annotations and some are validated using custom JQuery.
In the case that one of the fields with custom validation fails it's validation I wish to prevent the form from posting back however this stops any of the fields with Data Annotation Validation from working.
Thanks.
IMHO mixing jquery validate with MSAjax is a bad thing. For complex forms with many custom validation rules I would recommend using only jquery validate and on the server a more powerful validation framework than DataAnnotations such as FluentValidation.NET which works nicely with ASP.NET MVC.