Is it possible to use a data-annotation attribute for dropdownlists to be valid, only if the user selects an option different from one with the value o (zero).
The option with value o (zero) is "Please Select an account", which is selected by default.
I used [Required] attribute to validate this dropdownlist, but it doesn't have any effect, because, how I said, by default the option with value o (zero)- "Please Select an account"- is selected.
Something like:
[Range(1, int.MaxValue, ErrorMessage = "Please enter a value bigger than {1}")]
public int Value { get; set; }
Making a drop-down list required does not make sense. What you want required is that the user pick a value other than zero from the drop-down list. So what should be required is the SelectedAccount property. You should use the MVC helper method to bind the drop-down selected value to the SelectedAccount property:
#Html.DropdownListFor(m => m.SelectedAccount, new SelectList(Model.Accounts))
I am probably off on the syntax but you can look that up.
Now with regards to your other issue of ensuring that the value is not zero. Is the account number represented as a number or can it contain non-numeric characters? If it is a number then you should represent it as such in your code. And if it is truly a string, then the first value of your drop-down list should be an empty string and not zero.
If you decide that it is a number, then use the Range annotation to ensure that the value is greater than zero:
[Required]
[Range(1, Int32.MaxValue)]
public string SelectedAccountNumber {get;set;}
Hope that helps!
Related
I am having kendo mvc grid and one of its column is numeric text box and it is of type integer , but when I try to give decimal values to numeric text box ,it is becoming zero , but it should get rounded to nearest integer or should not accept decimal values.
How can i do that , kindly anyone help me
CODE:
columns.Bound(c => c.Quantity).Title("Quantity").Width(100);
public int Quantity { get; set; }
I am working on a system in Oracle Apex 22.1 where there is a Form, where the user enters an amount of money to be validated by the company. There are 3 fields which are a select list P3_REQUEST_TYPE, a text field P3_AMOUNT and a select list P3_TYPE_CURRENCY. What I want to do is that if the user selects the option "Payment Request" in P3_REQUEST_TYPE, and according to the amount entered in P3_AMOUNT and the type of currency in P3_TYPE_CURRENCY (USD, JPY), put the value "1" in the field P3_FG_RT for validation reasons.
I would like to know if there is a way to do it through a IF function since through dynamic actions I have not been able to make it work, I would greatly appreciate your help.
The amounts for the "1" to be placed are: if it is greater than or equal to 5,000 and they are USD, or if it is greater than or equal to 18,000 and they are JPY.
That looks like dynamic action, indeed.
its action would be "Set value"
type might be PL/SQL Function body:
RETURN CASE WHEN :P3_REQUEST_TYPE = 'Payment Request'
AND :P3_TYPE_CURRENCY IN ('USD', 'JPY')
THEN 1
END;
items to submit: P3_REQUEST_TYPE, P3_TYPE_CURRENCY
affected elements: item, P3_FG_RT
Though, as you said that these are Select List items, I kind of doubt that return values really are "Payment Request" or "JPY" - I presume that you actually return their codes, not descriptions so CASE expression might need to be changed.
The decision to use a dynamic action depends on the following question: is the value that needs to be set of importance before the page is submitted or does it only matter at submit time
#Littefoot explained how to do the dynamic action but if this value is only needed after the page is submitted, it is easier to set the value of page item P3_FG_RT with a a computation (process point After Submit).
One way to implement this computation is:
Type: Static Value
Static Value: 1
Server Side Condition: Expression
PL/SQL Expression:
:P3_REQUEST_TYPE = 'Payment Request' AND :P3_TYPE_CURRENCY IN ('USD', 'JPY')
I'd like to know how do you guys get a value from a number field through index search.
I'm using WebForms for my project currently I have this model
[IndexField("SomeNumber")]
int SomeNumber { get; set; }
and obviously a number field named "SomeNumber" in my sitecore item. But the thing is I only get 0 value for SomeNumber when I input a number on the field and a null when not. Note that I'm getting right values for my string fields so I'm not sure why the number field doesn't work right.
Thanks
I'm using validations as below.
[Required(ErrorMessage = "Please provide 10 digit mobile number without spaces and without country code (+91)")]
[Integer(ErrorMessage = "Please provide 10 digit mobile number without spaces and without country code (+91)")]
[Range(1000000000, 9999999999, ErrorMessage = "10 digit mobile number only without spaces and without country code (+91)")]
[Display(Name = "Mobile Number")]
public int MobileNo { get; set; }
It is always failing the validations saying The value '9999999998' is invalid.. Am I doing something wrong?
Try this:
[RegularExpression("^[0-9]{10}$", ErrorMessage = "Invalid Mobile No")]
The maximum value that an Int32 type could store is 2,147,483,648. You are overflowing. Why are you using an integer type to represent a phone number? String seems more adapted.
The Max Value an Integer(Int32) can hold is 2,147,483,647. So you should better replace Int with Long or String.
I wanted to change the grid column sequence dynamically. For e.g. By default the grid will be loaded in LoginId, FirstName and LastName sequence. Based on some condition, I need to change the FirstName and LastName sequence.
Is there any way I can do this?
I tried doing like:
{name:'UserName',index:'UserName',width:82,sortable:false},
if(true)
{
{name:'FirstName',index:'FirstName',width:65,sortable:false},
{name:'LastName',index:'LastName',width:65,sortable:false},
}
else
{
{name:'LastName',index:'LastName',width:65,sortable:false},
{name:'FirstName',index:'FirstName',width:65,sortable:false},
}
but I could not get this work.
You can use remapColumns function to do this. In the documentation of the function you will find the example which seems to be wrong, because indexes in the permutation array seem to be 1-based and not 0-based. Try to use:
$("#list").remapColumns([1,3,2],true,false);
or
$("#list").remapColumns([1,3,2,4,5,6,7,8,9],true,false);
if you want to change the order of the second and third from the total 9 columns.