"The field width must be a number." at client side - asp.net-mvc-3

I am using jquery for client side validation together with data annotations. Everything is working fine but I would like to localize a message when a non numeric value is entered in numeric textbox. But for client side validation asp.net mvc is using it's own resource file with key 'ClientDataTypeModelValidatorProvider_FieldMustBeNumeric'.
How can I do?
Thanks.

Look for solution at the end of this page:
http://jwwishart.wordpress.com/2010/03/22/custom-server-and-client-side-required-validator-in-mvc-2-using-jquery-validate/
I checked this in my MVC 3 RTM project and it works well.

I had the same problem because I'm Italian and here decimal numbers are formatted with comma instead of dot. So, what in the US is 1,000.12 here is written 1.000,12.
That's how I solved, after some searching:
MVC3 already includes the script jquery.validate.js/jquery.validate.min.js
and that's amazing.
Then I added another script -- methods-it.js -- taken from jquery validate plugin localization folder and changed a little.
jQuery.extend(jQuery.validator.methods, {
date: function (value, element) {
return this.optional(element) || /^\d\d?\.\d\d?\.\d\d\d?\d?$/.test(value);
},
number: function (value, element) {
return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:\.\d{3})+)(?:,\d+)?$/.test(value);
},
range: function (value, element, param) {
var val = value.replace(",", "#").replace(".", ",").replace("#", ".");
return this.optional(element) || (val >= param[0] && val <= param[1]);
}
});
This small code deals with dates (Italian formatting), floating numbers and range of values.
It works great, now!
Unfortunately this is just a direction and not THE solution, because it has to be corrected for every locale.

I found it easier to just use DataAnnotations on the view model:
[RegularExpression("([0-9]+)", ErrorMessageResourceType = typeof(ErrorMessage), ErrorMessageResourceName = "NumberInvalid")]

Related

convert decimal value from database into autonumeric in input value when edit

Hello i've been trying to call my decimal value from my database and put it back into autonumeric with thousand separator value when user tried to edit it, here for example :
here are the input value when user try to create new order :
And here was the input value when user try to edit the order, and the data will be NULL in the database when user submit the value, even with the decimal inside the value :
It change the value into decimal value from the database, and when user tried to hover the input it completely remove the value like this :
here is the index.blade.php which is the value is taken from database :
$('body').on('click', '.editMediaOrder', function(){
var id = $(this).data('id');
$.get('media-order/'+id+'/edit', function (data){
$('#modalHeading').html("Edit Media Order");
$('#btn-update').val("Update");
$('#editMediaOrderSubmitButton').val("edit-media-order");
$('#editMediaOrderSubmitButton').prop('disabled',false);
$('#editMediaOrderModal').modal('show');
$('#editMediaOrderModal').modal('hide');
$('#id_edit').val(data.id);
$('#nomor').val(data.nomor);
$('#nomor_reference').val(data.nomor_reference);
$('#periode_start_edit').val(data.periode_start);
$('#periode_end_edit').val(data.periode_end);
$('#category_id').val(data.category_id);
$('#type_id').val(data.type_id);
$('#agency_code').val(data.agency_code);
$('#agency_name').val(data.agency_name);
$('#advertiser_name').val(data.advertiser_name);
$('#advertiser_code').val(data.advertiser_code);
$('#brand_code').val(data.brand_code);
$('#brand_name').val(data.brand_name);
$('#version_code').val(data.version_code);
$('#nett_budget').val(data.nett_budget);
$('#gross_value').val(data.gross_value);
$('#nett_cashback').val(data.nett_cashback);
$('#nett_bundling').val(data.nett_bundling);
$('#spot').val(data.spot);
$('#accountexecutive_name').val(data.accountexecutive_name);
$('#group_id').val(data.group_id);
$('#userto_name').val(data.userto_name);
$('#notes').val(data.notes);
$('#attachment_name').val(data.attachment_name);
})
});
i've been trying to using jquery and ajax to create the thousand separator at first but ended up using an autonumeric instead, is there was a way to convert the decimal value from database into autonumeric with thousand separator, so that user wont have to input another value and the database will also recognize it?, thank you for your time, and forgive me if there was an spelling error, thanks again!.
function defineMaskMoney() {
$('.your input class').maskMoney({thousands: '.', decimal: ',', affixesStay: true});
}
this is for query money format.
number_format($yourprice, 2, ',', '.');
this is for backend format to money.
Been trying to find out myself that in the end i'll ended up using jquery number, which is very helpfull, and i just change some of my input to this in my index.blade.php :
$('#nett_budget').on('input',function(){
var nettbudget = parseInt($('#nett_budget').val());
var nettcashback = parseInt($('#nett_cashback').val());
var nettbundling = parseInt($('#nett_bundling').val());
var grossvalue = parseInt($('#gross_value').val());
});
and :
$(function(){
$('#nett_budget').number(true);
$('#nett_bundling').number(true);
$('#gross_value').number(true);
$('#nett_cashback').number(true);
});
thanks again for helping me, and your time for reading my question.

Display location based currency identifiers in text field placeholder

Basically within my app I have two text fields for pound and pence value inputs. I am currently working on making my app localised and I have ran into an issue. My textfields have the placeholders 'Pounds' and 'Pence' and I need them to display placeholders for the currency and sub-currency based on the users location such as 'Dollars' and 'Cents' for the US.
I have no idea how to do this in a way that would be efficient and I was hoping for some suggestions as to how I could go about this.
Any help would be much appreciated!
You can get the name of the local currency by using NSLocale:
var locale = NSLocale.currentLocale()
var currencyCode: (AnyObject!) = locale.objectForKey(NSLocaleCurrencyCode)
locale.displayNameForKey(NSLocaleCurrencyCode, value: code) // "British Pound"
However, it seems that you may not be satisifed with the official name and I am not aware of a way to get Pence or Cents so you can also create your own list using locale identifiers:
struct LocalCurrency {
static func wholeName(forLocale locale: NSLocale = NSLocale.currentLocale()) -> String {
var identifier : String = locale.localeIdentifier
switch(identifier) {
case "en_UK":
return "Pounds"
case "en_US":
return "Dollar"
default:
return ""
}
}
}
LocalCurrency.wholeName() // "Pounds"
You can create a similar method for partial currencies and you will have to add all locales you want to support manually, but at least the device will tell you what the current Locale is.
Update:
You can also get the currency symbol:
locale.displayNameForKey(NSLocaleCurrencySymbol, value: code) // £
Or you can use an NSNumberFormatter to format currency for you:
var formatter = NSNumberFormatter()
formatter.numberStyle = .CurrencyStyle
formatter.stringFromNumber(1.23) // £1.23
Perhaps you can use one of those to come up with a new format for how you want to display it without creating a manual list.

How to get value of dynamically added fields while doing Form Editing in JqGrid

I have one jqgrid which is having few columns. One of the column represent URLs. While showing the data in grid format, every url apears one after another seperated by ;(semicolon). When I double click a row, I get Form Window and in block onInitializeForm based on number of ;(semicolon)'s count, I am showing every URL in different inputbox. So the user can edit/update each one individualy.
But I am getting problem when there are more than one URL entry and after making changes when I submit the window, I get only first URL's data in my beans attribute. Others just get disappeared.
I saw the postdata in 'beforeSubmit' method and this is also showing only first input box's value.
Could you please help me, how to get value from those dynamically added extra fields?
If you need more info, please tell me. I am stuck on this for more than three days.
Update :-
What I did is,
in
beforeSubmit : function(postdata, formid) {
var val=";";
$("p textarea").each(function (index) {
val = val + $("#p_scnt" +(index+1)).val() + ";";
});
$('#url').val($("#url").val() + val);
return[true, ""];
}
"url" is my jqgrid column and "p_scnt" is the id of all newly created textboxes.
Its not setting valud back to URL column
I solved it using another way.
beforeSubmit : function(postdata, formid) {
var val=";";
$("p textarea").each(function (index) {
val = val + $("#p_scnt" +(index+1)).val() + ";";
});
postdata["url"] = postdata["url"] + val;
return[true, ""];
}

Getting strange exception in OpenXml SDK 2.5

I have a simple file *.xlsx created in Office 2010 with 3 spreadsheets. Only first is used and have easy formula like Sum and Multiplication in cells. It also contains 17 columns and 4k rows filled. Data types of the cells are: Numeric, Short Date, Long Date and Text. When I'm trying to read that file using OpenXml SDK 2.5 and validate it to make sure this file is correct I'm receving this strange exception:
ErrorType: Schema.
Error Description: The attribute 'verticalDpi' has invalid value '0'. The MinInclusive constraint failed. The value must be greater than or equal to 1.
This is method how I'm reading and validating:
VB.NET:
Using spreadsheet As SpreadsheetDocument = SpreadsheetDocument.Open(m_FileName, False)
Dim validator As New OpenXmlValidator
Dim errorsValidation As IEnumerable(Of DocumentFormat.OpenXml.Validation.ValidationErrorInfo) = validator.Validate(spreadsheet)
If Not errorsValidation.Any() Then
'Do something here if it's correct
Else
Console.WriteLine(errorsValidation.First().Description)
End If
End Using
C#:
using (SpreadsheetDocument spreadsheet = SpreadsheetDocument.Open(m_FileName, false)) {
OpenXmlValidator validator = new OpenXmlValidator();
IEnumerable<DocumentFormat.OpenXml.Validation.ValidationErrorInfo> errorsValidation = validator.Validate(spreadsheet);
if (!errorsValidation.Any()) {
//Do something here if it's correct
} else {
Console.WriteLine(errorsValidation.First().Description);
}
}
I don't know what I'm doing wrong and what is wrong. Can't find any issues to how to fix the file. Any idea, suggestions?

Telerik MVC Extensions Grid Aggregate with Ajax Binding returns zero

Well, i decided to give it a try to Telerik MVC Extensions v.2012.2.607.340
I am having a problem with aggregating a decimal field in their grid.
I am using ajax binding.
I have an Action that returns a json
return Json(data);
data is nothing but a List. it converts into json without problems. My grid is showing the data but the aggregation is not working. returns 0 (zero).
i am following their examples here
I went to their forum/community but i couldn't find any solution to this. maybe they dropped the ball since they made it into Kendo something and they are charging a "grand" for it.
Anyone has had the same problem?
Thanks
You need to return something like this:
return Json(new {
Data = typeof(IEnumerable),
Total = typeof(int),
Aggregates = typeof(Dictionary<string, object>)
});
You need to precalculate Aggregates though. Key of a Dictionary is name of the field, and its value is calculated aggregate.

Resources