How can I validate the value of time using form validation engine? I'm using a timepicker (http://trentrichardson.com/examples/timepicker/) plugins to insert date and time in same field that gave a value of "2011-05-25 00:00:00" 00:00:00 is a default value if the user not tick on the slider.
time must not be in "00". Do i need to trim the value to validate it? I'm stuck with this. Please help.
jQuery.validator.addMethod('time', function(value, element) {
return this.value.search(/00:00:00$/) != -1;
}, 'Please enter a valid time.');
Related
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.
I am trying to add a date conditional to my controller index action:
#events = Event.where("date" => Date.today.to_s).order("date").page(params[:page]).per_page(5)
I am trying to make my view only show events that have a date value greater than or equal to today's date. For example if an event has a date value of 2013-05-13 it should not be shown because that event has already happened and only events with a date value of today's date or later should be shown.
The problem is, the index view isn't returning any events and I have created an with a date value of 2013-05-30 which means it should work. Any ideas?
Thanks in advance
This is actually going to return everything where the date equals today:
Event.where("date" => Date.today.to_s)
What you probably want instead is:
Event.where("date >= ?", Date.today)
ActiveRecord will interpolate the date into the ?. Also, you don't need to call to_s on it, ActiveRecord will the date for you.
Try this:
In your model use a scope like so:
scope :recent_event, lambda { where('date >= ?', Date.today ) }
Then in your controller write
#events = Event.recent_event.order("date").page(params[:page]).per_page(5)
Is it possible to execute validations on page load regardless if it is submitted or just loaded?
I need to implement it for ordinary validations created in processing page section and for min max validations assigned to number field.
Is it possible to implement?
Indeed: having a server side validation will throw an error, but the page has submitted and thus the changed values are in session state. You could try to prevent this by having a plsql validation which would blank out the session state value when an error occurs, but might not be optimal. I think that some javascript could alliviate some of the trouble.
Here is some javascript that restricts the selectable ranges in the to and from datepickers. It won't allow a user to pick a larger from than to date, and vice versa. It also sets the item to readonly, so that the user has to select through the datepicker and can not alter it by hand.
Page > Javascript > Function and Global Variable Declaration
function f_check_date(){
var lFrom = $("#P6_DATE_FROM").datepicker("getDate"),
lTo = $("#P6_DATE_TO").datepicker("getDate");
if(lFrom > lTo || lTo < lFrom){
//in case it does happen
$("#P6_DATE_FROM").val('');
$("#P6_DATE_FROM").val('');
alert('Please select a valid date range.');
} else {
//when a date changes, the other datepicker has to be altered so the
//range is adjusted
$("#P6_DATE_FROM").datepicker("option","maxDate",lTo);
$("#P6_DATE_TO").datepicker("option","minDate",lFrom);
};
};
Dynamic Action, Page Load, Execute javascript
//on load, set the datepicker range in case a date is already present
//when the date changes, call the datecheck function
//and set item to readonly
$("#P6_DATE_FROM")
.datepicker("option","maxDate",$("#P6_DATE_TO").datepicker("getDate"))
.change(f_check_date)
.prop("readonly",true);
$("#P6_DATE_TO")
.datepicker("option","minDate",$("#P6_DATE_FROM").datepicker("getDate"))
.change(f_check_date)
.prop("readonly",true);
I have a string date value of 3/2/2013 when using the Kendo DatePicker and Date(-62135578800000) from the when encoded to the array. I am binding a Kendo array to a template and would like the date to be user friendly, like "Sat, Mar 2". I have tried toString and ParseDate with no luck. I created a fiddle, http://jsfiddle.net/srakestraw/Q3MF8/, but can't figure out what I am doing wrong.
When I load the page, I get a date values like Date(-62135578800000) using Json.Encode, see below.
var viewModel = kendo.observable({
slots: #Html.Raw(Json.Encode(Model.Slots))
});
On the front-end, the user selects a date using the KendoUI datepicker and I push the value the the array. Am I using the wrong date format?
Thanks for any help.
The problem is that Date(-62135578800000) is not a valid JavaScript Date object:
alert(typeof Date(-62135578800000)); // string
Here is the updated jsfiddle: http://jsfiddle.net/Q3MF8/3/
This will format dates in a manner you can work with (ISO 8601) instead of those hideous Json.Encode formatter monstrosities.
#Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model))
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")]