Angularjs form with "name" attribute set, ignores default values - forms

To validate a form in Angularjs, the "name" attribute needs to be set on the form. When the "name" attribute is set, setting default values in the controller won't work anymore.
Here's an example to demonstrate:
http://plnkr.co/edit/Q59yBZFIGWPMveYuez52?p=preview
On the first form, I have set no "name" attribute, which will set the default value correct, but will not have a validation object when I submit the value.
On the second form, I have set the "name" attribute, which will not set the default value correct, but will have a validation object when I submit the value.
Is this expected behavior or a bug?

The form controller is put in the $scope with the given name. So in your case, the name of the model collides with the name of the form and strange things happen; this is a timebomb, a bug that will haunt you sometime in the future.
I like giving forms a distinct name; if you try <form name="user2form"> in your fiddle, it will work. (I always suffix the form name with form for this reason.)

Related

Vue Element UI - Default el-input-number to empty field instead of a number

Creating a form with no values and would like the input field to default to empty for two reasons:
Want users to be able to see the placeholder text.
Having a default number means the users can ignore the field by default. (I know I can validate the field, but that is just a bad user experience.)
The problem:
el-input-number fields default to a number (0 or whatever the :min value is set to).
This covers up the placeholder text.
The users can click save with the default number still in place. (I will validate, but don't want users to have to submit a bad value to know what to do.)
Does anyone know how to make the input field have the default value be just empty?
just give it a default value of undefined
https://codepen.io/rugia/pen/bGEoWaB?editors=1010

redux-form Wizard form with linked fields

I am building a multi-step application form with React. Having first built it with pure internal state I am now in the process of refactoring to Redux using redux-form.
Having used the example here as a basis: http://redux-form.com/5.2.5/#/examples/wizard?_k=oftw7a we have come a good way.
However the problem appears when i have two forms which are supposed to have the same value. During one of the pages i have a name field, that is supposed to be duplicated on the name field of the next page. The opposite should happen if you go back from the last page. Any tips to how this could be achieved?
Using the wizard, you are basically working with the exact same form that's split into multiple pieces. Ultimately it's the same form, because redux-form tracks them by name. It is how the library identifies the pieces of the same form - using the name.
form: 'wizard',
Here you can see that the exact same instance of the form will be shared throughout the pieces. fields work in a similar manner. Each field is defined as part of a form.
As long as you use the same field constants inside the fields object that you pass into the reduxForm function and as long as the value for form is the same, so that they use the same underlying form object, it should work for you just fine.
On one page you should pass in
export default reduxForm({
form: 'wizard',
fields : {
'fieldIWantOnBothPartsOfTheForm',
'someOtherFieldThatShouldOnlyBeHere',
},
...
And then on the other page:
export default reduxForm({
form: 'wizard',
fields : {
'fieldIWantOnBothPartsOfTheForm',
'thirdFieldHere',
},
...
Also, make sure you keep destroyOnUnmount equal to false if you want to navigate back-and-forth.
Hope that helps.

InfoPath 2010 How to avoid validation when a section is hidden?

I am trying to design an info path form that links to a share point list.
I have a "extra" section on the form which is only visible if a check box value = true.
The problem is some of the fields on the "extra" section is mandatory. So when the check box value = false, the section is hidden and I cannot fill in the fields. But when I try to submit the form I get an error message to say mandatory fields must be completed. But I do not want to complete those fields.. as the section is to be kept hidden.
Any suggestion on how to get this working would be very helpful thanks.
Do not add the required field checkbox instead create a validation rule that checks if your value is true and the hidden field is empty then send a required error.
This way you can submit the form.
put a sample value on that field like "none" then when the section is checked, set a rule that will clear that field.

Define default value for plain input field (Templavoila)

I tried to set the field "Sample Data" on the "Configuration" page when mapping a data element with Templavoila. But it seems it is used for something else.
Is it possible to define default values for fields like "Plain input field"?
Open the Templavoila DS/TO editor, select your field and add following to "Form"
<default>Your default value</default>
Heres an example:

ValidationMessageFor returns no information when calling modelState.AddModelStateError

I created a class that implements the IModelBinder interface. Within a method of that class I basically retrieve some values and try to validate them. If the validation fails, I add update the model state with necessary information like below:
DateTime mydate;
if (!DateTime.TryParse(convValue,out mydate))
{
bindingContext.ModelState.AddModelError("Date", "Date was crap");
}
The problem is that Html.ValidationMessageFor(m => m.Model) returns no value. I looked at the MVC source code and found out that a proper key with id "Date" can't be found in the ModelState dictionary.
Why is that ? The controller that returns the view have access to the model state and can enumerate over ModelState.Errors
Thanks,
Thomas
Is "Date" the name of the property you are validating?
The first parameter of ModelState.AddModelError should either be the name of the property you want the validation message to display for, or left as string.Empty if you only want the error to display in in the validation summary.
If you want to display an error message that isn't tied to a specific property of your viewmodel, you could call <%: Html.ValidationMessage("Date") %> in your view to display that particular message if it has been set.
Edit: just realised how old this question is. Ah well, might come in handy anyway...