JQGrid remove value from custom error message - jqgrid

In inline navigation, i want to remove user entered value from custom error message.
So far all examples have this sticked to message.
For e.g. I want to remove date "2013-blah blah"
(source: easycaptures.com)
Thanks.

You can use custom_func to achieve this.
Add editrules to column details in colModel like given below
editrules:{custom: true, custom_func: customValidationMessage}
and the function (In this case I am doing validation for required, you can do your validation for date in if condition )
function customValidationMessage(val, colname) {
if (val.trim() == "") {
return [ false,colname + " is required " ];
} else {
return [ true, "" ];
}
}

Related

Yup validation with one field but two possible options (OR)

I am trying to create an input that takes a string that will be used as the href value for a tag. The href can be a url OR an email (for mailto:).
It works if I just check for email, or if I just check for URL. However, I want to check for one or the other. I am looking through yup documentation but I can't find a way to do an OR.
I noticed that there is a when to test for another field but I'm not checking if another field is true or not, or use test but I also can't seem to get it to work.
const vSchema = yup.object().shape({
text: yup.string().required(),
href: yup
.string()
.email('Link must be a URL or email')
.url('Link must be a URL or email')
.required('Link is a required field'),
});
test this
yup.addMethod(yup.string, "or", function(schemas, msg) {
return this.test({
name: "or",
message: "Please enter valid url or email." || msg,
test: value => {
if (Array.isArray(schemas) && schemas.length > 1) {
const resee = schemas.map(schema => schema.isValidSync(value));
return resee.some(res => res);
} else {
throw new TypeError("Schemas is not correct array schema");
}
},
exclusive: false
});
});

Semantic-ui form rule only if option is selected

I am using semantic ui and am trying to do some form validation with it.
The scenario I have is the user has 2 options: email,or phone app verrifcation. They select one of the options and enter whatever in a text field then click submit.
However I am not sure how to do rules on this with semantic UI.
I know if I wanted to check if it was blank I could do something like this:
$('.ui.form')
.form({
fields: {
CODE: {
identifier: 'code',
rules: [
{
type : 'empty',
prompt : 'Please enter your verification code'
}
]
}
} } );
However I would like additional rules based upon which option is selected. I have javascript that currently tells me the value of what is selected, and is updated on change. Unsure how to add it into the rules though, so that I can be like -- If phone was select, must be exactly 6 chars long, or IF email was selected, must be 18 chars long (different lengths for different option).
Is there a way to have conditional rules like this? Closet I could find was:
depends: 'id'
Which checks to ensure it is not empty.
Does anyone know how to have conditional rules such as this based on another form element? I am using the most recent version of Semantic-UI
You can do so by adding custom rules.
$.fn.form.settings.rules.atLeastOne = function (value, fields) {
fieldsToCompare = fields.split(",")
if (value) {
// current input is not empty
return true
} else {
// check the other input field(s)
// atLeastOne is not empty
atLeastOne = false
for (i = 0; i < fieldsToCompare.length; i++) {
// gets input based on id
if ($("#" + fieldsToCompare[i]).val()) {
atLeastOne = true
}
}
return atLeastOne
}
}
$(".ui.form").form({
fields: {
number:{
identifier: "number",
rules: [{
type: "exactLength[6]",
prompt: "number has to be 6 chars long"
}, {
// include the input fields to check atLeastOne[email, address, ...]
type: "atLeastOne[email]",
prompt: "Please provide an email or a number"
}]
},
email: {
identifier: "email",
rules: [{
type: "exactLength[18]",
prompt: "email has to be 18 chars long"
}, {
type: "atLeastOne[number]",
prompt: "Please provide an email or a number"
}]
}
}
});
Note that the function uses the input id as the identifier and not the input name. You might also want to look at optional fields.

Custom Filter records in Free-jqgrid 4.15.4

I have one question regarding custom filters in free jqGrid 4.15.4. I want to implement a search functionality where if I select 'less than but not null or empty' filter then it should show only rows of records which column isn't null or empty. I am able to create custom filter which gives 'is null' or 'isn't null' from this thread.
But when I tried to create for mine requirement, I wasn't able to figure out what operator I have to use for 'less than but not null or empty'.
for example, I have used this code sample to create custom filter:
customUnaryOperations: ["lne"],
customSortOperations: {
lne: {
operand: "<!=''",
text: "less but not empty",
filter: function (options) {
var v = options.item[options.cmName];
if (v !== undefined && v !== "") {
return true;
}
}
}
The above operator I've used in search option toolbar.
searchoptions: {
searchOperators: true,
sopt: ['eq', 'lt', 'gt','lne'],
}, search: true,
Meanwhile, I don't want to use formatter: "integer" (suggested here) as this only assigns 0 to all null record column cells, and still visible in records whenever one selects 'less than' filter .
For reference, I've created one fiddle which consists of the requirement and two images for more clarity. So, Can anyone help me out on this? I hope I'vent re-asked this again.
Thank you in advance.
The code of the filter could be like the following
customSortOperations: {
lne: {
operand: "<!=''",
text: "less but not empty",
filter: function (options) {
var v = options.item[options.cmName];
if (v !== undefined && v !== "" &&
parseFloat(v) < parseFloat(options.searchValue)) {
return true;
}
}
}
}
See modified demo https://jsfiddle.net/OlegKi/x3fger4z/17/

datatables yadcf custom function not triggered

I'm using datatables and the yadcf plugin which is working well. However I'm trying to add a custom filter and having no luck getting it to work. It appears it is being ignored.
Basically I want to filter whether a cell is empty or has data
I used this example as a starting point:
http://yadcf-showcase.appspot.com/DOM_source.html
My custom function is:
function filterGroupName(filterVal, columnVal) {
var found;
if (columnVal === '') {
return true;
}
switch (filterVal) {
case 'Groups':
found = columnVal.length > 0;
break;
case 'No Groups':
found = columnVal.length < 1 || columnVal === '';
break;
default:
found = 1;
break;
}
if (found !== -1) {
return true;
}
return false;
}
And here is the part of the script that sets up yadcf:
{
column_number: 3,
filter_container_id: "filter-group-name",
filter_type: "custom_func",
data: [{
value: 'Groups',
label: 'Groups'
}, {
value: 'No Groups',
label: 'No Groups'
}],
filter_default_label: "Select Groups",
custom_func: filterGroupName
}
I've set a breakpoint in the script to see what's happening but it never gets triggered
The page gets the correct select boxes created but selecting either option returns no entries - everything is being filtered out in the datatable.
So, what have I missed in getting the function to work?
Thank you
I'm managed to work out the problem.
During development I modified the data property of yadcf for the column to that above. However I had state save set on datatables so the original filter was being used - ignoring any changes I made to the strucuture of the new filters and the resulting code.
I removed state save and the filter came to life!

Assistance with a custom jquery validate error message function

We have a rule that all of our validation messages must be in a summary, and thus the default "this field is required" doesn't cut it because the messages lose their context in a summary and therefore need specific field indicators.
I have a solution that I like rather well, but it soon became clear that there was a need for messages outside of just the required field (email, url, custom methods like phoneUS, etc), so I made some additions to my function.
I've been using jQuery for a while, but I'm not an expert in the optimization area, so I wanted to get some expert help on whether the function below could be optimized...my question is, "is there actually a better way to handle custom error messages in a summary?"
$('.required, .email').each(function(index) {
var $this = $(this);
var label = (
$this.is(':radio')
? $("label[data-name='"+$this.attr('name')+"']")
: label = $("label[for='"+$this.attr('id')+"']")
);
var customMessages = [{}];
if($this.hasClass('required')){
customMessages.required = "'" + label.text() + "' is required.";
}
if($this.hasClass('email')){
customMessages.email = "'" + label.text() + "' has an invalid email address.";
}
$this.rules("add", {
messages: customMessages
});
});
Here is the jsFiddle:
http://jsfiddle.net/GD5nw/1/
So why not just assign the custom message on a field-by-field basis for each field as is most typically done? It seems less verbose than what you've been doing.
http://docs.jquery.com/Plugins/Validation/validate#toptions
Example for input elements with name attribute assigned as first, second, and address.
$('#myform').validate({
rules: {
first: {
required: true
},
second: {
required: true
},
address: {
required: true,
digits: true // just an example
}
},
messages: {
first: {
required: "your first name is required"
},
second: {
required: "your last name is required"
},
address: {
required: "your address is required",
digits: "must only use digits on address"
}
}
});
Working Demo: http://jsfiddle.net/x4YBw/

Resources