Joi Validation Accepts undefined When Required - forms

I have a validation issue I am hitting while using Joi. I have a set of number fields that begin with a value of undefined but are ultimately required. However, Joi still accepts the undefined values upon submit.
expenses: Joi.number().min(0).max(9999999).required()
I have found that once I load the form and click submit, the values are accepted. However, if I type into a field, say 1 and then backspace to remove it, then the field does error on submit.
Any way I can get the undefined to trigger the error on the number field with the initial submit?

Related

Solution to Failure to Obtain an Input Value

When I entered a value in the input box and submitted it, the mandatory item verification failed, and the system displayed a message indicating that a parameter was empty and instructed me to enter a value. The code for obtaining the input value is as follows:
(see the solution in column C)
can you give me some advice about it?
The possible cause is that the method for obtaining the value is incorrect. As a result, the value in the input box cannot be obtained.
Use the onchange event to assign a value to the model and obtain the value of the input box. The method is as follows:
Initialize the model.
data:{
accountValue:''
}
Bind an event to the input box.
<input #change="getAccountValue" value="{{accountValue}}"></input>
Assign a value.
getAccountValue: function(e) {
this.accountValue = e.value // Here, e.value instead of e.target.attr.value is used.
}
Refer to the official document instead of generating a JavaScript object for coding. A JavaScript object may lead to compatibility issues.
Currently, the data binding mode of the quick app is unidirectional.
The value entered in the input box does not change the value of accountValue in data.
If the value of the input box is changed by setting this.accountValue to xxx, the onchange event of the input will not be triggered.
In this.accountValue = xxx format, if the value of accountValue before and after the change is the same, the page will not be re-rendered.

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

set user defined field in QuickFIXn NewOrderSingle()

i want to close a position and construct a New-Order-Single message. but failed to add a user-defined field (9041=_ID) to this message(other
predefined fields have been added successfully).anyone has idea about this?

Parsley.js - Re-validate a field after selecting an auto-complete value or drag-and-drop

After parsley validation, an error message may be displayed near a field.
If the user types a corrected value, the field is automatically re-validated, the message will disappear, and the field will be marked with success.
However, if a valid value is then entered by either i) selecting from the field's "auto-complete" dropdown OR ii) by dragging-and-dropping into the field, this will not invoke the re-validation, and the error message remains even though the field now has a valid value.
Example...
Q: How to force fields to re-validate upon selecting value from the browser's auto-complete dropdown/drag-and-drop?
(I realise you can specify no auto-complete on fields, but this may not always be desirable, and doesn't solve the drag-and-drop issue.)
In autofill function add this code to validate the autofill fields again:
function autofill_function_name(){
your code;
$("#autofill_field_name").parsley().validate();
}
In my case, I use bootstrapValidator for validation.
Then, you have to revalidate the field after fetching data
$('yourForm).bootstrapValidator('revalidateField', 'inputName');

When using ['#access'] in hook_form_alter() for a field than I am loosing '$form field default value' and $form_state input

When using an EntityReference field and in hook_form_alter() hiding that field with ['access'] than after submitting form $form_state input is empty for that field.
I have field field_to_a which is an entityrefence field on content type B that references content type A.
I am using hook_form_alter() in which i am using a line like $form['field_to_a']['#access'] = FALSE; and also setting this field to a certain value
When I am pressing submit button (my Save button) on node add:
When I am using $form['field_to_a']['#access'] = FALSE;: I am loosing $form_state['input']['field_to_a'] (does not exist) and $form['field_to_a']['und'][0]['target_id']['#default_value'] (empty) and I have PHP errors.
When I am using NOT $form['field_to_a']['#access'] = FALSE;: I have $form_state['input']['field_to_a'] properly and node is saved without any errors.
When I am using any other field I can use ['#access'] = FALSE and not loosing input in $form_state for that field.
Is there any solution or workaround for this thing? Is it a bug or normal behavior?
Thanks
First check log what you have received.
try this :
function hook_submit($form, &$form_state) {
watchdog("Your Form data ", '<pre>'.print_r($form_state, true).'</pre>');
}
Then check your log report. you will receive your value in $form_state['values']
It may helps you