I'm developing a project using Spring 3.0.
I have a form with several submit buttons.
What I would like to do is to have different validation requirements depending on the pressed button.
How do I do this? An example would be great.
Thanks
You can have multiple implementation of Spring Validator. And depending on the button clicked you can call validate method of required validator implementation from controller.
Here is a example of validation using spring validator.
Related
everyone.
I am developing app with angular and I am using Angular material for UI.
I know about angular validation
https://angular.io/docs/ts/latest/cookbook/form-validation.html
How can I validate md-select ?
You can validate md-select the same way it's shown in the documentation. The main idea is to create a reference #someName and the use that reference to do the validation. There are six controls that Angular provides: touched, untouched, dirty, pristine, valid and invalid.
I created a Plunker demo for you with the dirty validation for md-select.
You can read more about validation in the "Track control state and validity with ngModel" section, here: https://angular.io/docs/ts/latest/guide/forms.html
We are currently looking to experiment with modern frontend frameworks like react on an MVC4 project. We use data annotations in our models and we have a lot of forms that use unobtrusive validation on the UI.
The main thing is finding a way to use react to generate the content while still being able to make use of features like unobtrusive validation. As I understand it, it really is just a bunch of data-val attributes dynamically generated when using HTML helpers like TextAreaFor, ValidationMessageFor with the attributes getting values from the data annotations in the model classes.
I've tried several things including
ReactDOM.render(
#using (Html.BeginForm("xyz", "xyz", FormMethod.Post))
{
#Html.TextBoxFor(x => x.Email)
which results in the input box not being editable for some reason.
I'd prefer to do something more like
ReactDOM.render(
<form><input type="text" data-val="#Model.datannotations[1].val" /></form>
Is that possible? How does one get the data-val values from the model anyway? What is the best way to achieve this?
it should not be possible.
These are two differents ways to delvelop the ui.
The razor way is preprocessing the markup code in server side to fill it.
And react works in another flow using the lifecycle methods, you should have already loaded the data-anotations values for accessing it on render.
Therefore, to make this works you have to run razor engine first to fill the markup and next using react engine.
I don't recommend use this approach because it's too hard to develop on it and the developers team have to keep that flow in mind while they are developing
Note this
ReactDOM.render(<ComponentMustHaveJSX/>)
Can I disable spring MVC to generate hidden field for checkbox. I'm using Thymeleaf templates.
Thanks!
This is a fairly old question, but I just ran into this posting a Spring form that contained checkboxes with a GET action. My work-around also uses jQuery, which was not tagged in this question, but it did achieve the desired result.
The _checkbox hidden field was showing in the URL as a query string parameter. I ended up using jQuery to remove the Spring-generated hidden fields at page load, which cleaned up the URL on submit. I did not see any adverse behavior on the server side.
Very newbie question, but I'm finding it difficult to understand how checkbox States are maintained after a form post in razor mvc 5.
I've done it in PHP with session variables but for the life of me, can't find an easy to understand way in razor.
My situation is, view with checkboxes, form post handled by controller and postback to view with checkbox States from before form post set.
Thanks!
In Your controller you can check bool property of your checkbox by
if (model.check)
{
do something
}
What happens when using SpringMVC and the Spring Tag library does not have the tags you require? What can the developer use that will allow automated databinding, does the developer now have to use the old way of doing databinding which involves using the http *request*, response to get and set form elements?
Can the developer add to the Spring-Form tags? I am confused on how to approach this since i am using tags form html5 and they do not exist in the Spring Tag library.
Can someone advise me on the best approach to handling a problem such as this. I have been asking questions on how does one use a **<canvas>** tag in SpringMVC so that it allows automated databinding like spring <form> tags.
You can still get the binding done by providing the name attribute value of canvas tag same as the name of the field in your pojo you want to bind the value with.
Eg. if your field name in pojo is myCanvas, then you can give the same name in name attribute of canvas tag. So that the binding gets done.
Hope this helps you. Cheers.