I'm using jQuery-Validation-Engine to do some client side checking before sending a form to the server.
I know you can check to make sure two fields match using validate[equals[fieldId]] where fieldId is the id of the field you want to match. Useful if you want to make sure passwords match, for example.
Now I am trying to find a way to make sure fields don't match. For example, if I wanted to make sure a password field did not match a username field.
Has anyone been able to get this to work? Any other ideas?
Thanks.
After some research and trial and error, I answered my own question. I'll post what I did here so others who need to do the same thing will have a reference.
Turns out you need to create a new custom function in much the same way you add a custom regex. How to apply a custom regex is fairly well documented, but there's not much on how to implement a custom function (without calling a 3rd party function).
Digging around in the language file gives a better idea of how to handle it.
I had to create a custom validator with a function attached inside the language file (in this case jquery.validationEngine-en.js):
"notEqual": {
"func": function(field, rules, i, options){
return (field.val() == $('#username').val()) ? false : true;
},
"alertText": "* Username and password must be different"
},
In my html markup, I use it like this:
<input type="hidden" name="username" value="yourPassword" id="username"/>
<input class="validate[custom[notEqual]]" type="password" name="confirmPassword" value=""/>
Hope that helps someone.
Thanks for the help. You can also do this using funcCall.
In your case the HTML is:
<input class="validate[funcCall[notEqual]]" type="password" name="confirmPassword" value="">
and the function is:
function notEqual(field){
if(field.val() == $('#username').val()){
return "* Username and password must be different";
}
}
This might be useful for times when you have validation functions that can be re-used from other libraries or other areas of your code.
http://posabsolute.github.io/jQuery-Validation-Engine/#validators/funccall-methodname
Related
how can i use Mybatis selectKet funtionality in Node.js?
I wanted to use selectKey in xml file but it never works!
they just say "consider using Cdata"
but it's quite hard to find the way of using many ways to make query with node.js in mybatis.
somebody help me!
<select id="selectPositionNmData">
<selectKey keyProperty="result1" order="BEFORE">
SELECT
DIVN_NM
FROM
T_DIVN
WHERE
DIVN_CD = #{DIVN_CD}
</selectKey>
<selectKey keyProperty="result2" order="BEFORE">
SELECT
CONCAT("_", AUT_NAME)
FROM
qt_auth qa
where
SYS_ID = #{AUTH_SYS_ID}
</selectKey>
SELECT CONCAT(#{result1}, #{result2}) AS RESULT FROM DUAL;
</select>
I need to add a CSS class to a variant which is out of stock, that way I would know, before hand, which variant has or has not stock available.
I have been checking the detail page (specifically the buy_container.tpl file) to see if there's a clue in there. I used var dump to check the $sArticle.sConfigurator but it doesn't say if one of the variants is out of stock. I also checked the $sArticle.instock and $sArticle.isAvailable but as the detail page uses ajax to reload the data, those variables only work after selecting the out of stock variant, and I need to know which variant is out of stock before hand.
This is where I need to add the CSS class:
{foreach $sConfigurator.values as $configValue}
{if !{config name=hideNoInstock} || ({config name=hideNoInstock} && $configValue.selectable)}
<div class="variant--option {if $outofstock}OUT-OF-STOCK{/if} {if $configValue.selected}variant-selected{/if}">
<input type="radio"
class="option--input"
{if $configValue.selected} checked="checked"{/if}
value="{$configValue.optionID}"
name="group[{$sConfigurator.groupID}]"
{if $theme.ajaxVariantSwitch}
data-ajax-select-variants="true"{else}
data-auto-submit="true"{/if} />
{$configValue.optionname}{if $configValue.upprice} {if $configValue.upprice > 0}{/if}{/if}
</div>
{/if}
{/foreach}
Any clue would be appreciated,
Thanks.
Try to use the selection-configurator. With this configurator this information will be available. See: https://github.com/shopware/shopware/blob/5.5/themes/Frontend/Bare/frontend/detail/config_variant.tpl#L31
No other configurator will provide this data. When you want to use an other configurator, you need to implement such a variable/function yourself.
How can I use PromptDialog.Choice while allowing the user to type the options without worrying about accented letters?
Given the following prompt to the user:
List<string> promptValues = new List<string> { "Sim", "Não" };
PromptDialog.Choice<string>(context,
AfterPrompt,
promptValues,
"Digite 'Sim' ou 'Não'",
"Opção inválida, por favor tente novamente.");
How can I allow the user to input "Nao" or "Não" without the prompt considering "Nao" as a wrong answer?
I can't use PromptDialog.Confirm because I need the dialogs to happen in Portuguese, and as far as I know I can't localize PromptDialog.Choice.
Also I want to know how can I ignore accents even with other kinds of prompt, not only Yes or No prompts.
Is there a way to do this?
I believe you might be able to localize the PromptConfirm options if you change the culture of the bot like:
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("de-DE");
because the options are being retrieved from a resource file (see this)
Now, it seems that the Portuguese resource is not implemented yet, which from my point of view it could be something great to contribute if you want to.
On the other hand, if you want to have some custom logic in the PromptChoice, you can always inherit from it and override the TryParse method to add your checks. Here is an example of a custom PromptChoice.
res.render('home',o);
o={
name:"Free Lunch",
privilege:[3,4],
const:{
RESET:1,
ADD:2,
DELETE:3
MANAGE:4,
REPORT:5
}
}
I want to check if dust-helper if condition whether the value corresponding to REPORT which is 5 is present in the privilege array or not.
<#if cond="......">
Any idea how to do it?
You could iterate over the array and test each element but I can't think how you could use/store the fact after the iteration. I don't know a way to do this with the current language facilities but that is why custom dust helpers are provided. You could build a {#arrayContains key=array value=value} sort of helper. Since you don't say what you want to do once you determine the existence/non-existence, it is unclear what else the helper might do after the check.
{#if cond="('{con.REPORT}' && '{con.REPORT}'.length)"}I EXIST DO SOMETHING{/if}
Before you test, make sure to add a , after the DELETE attribute
I have an application written in groovy and I am having problems with the pagination of a resulting set.
I have a Controller called ReportingController. This controller has two methods called
listdoiTln and listdoiEv. Both methods are similar and at the end both have to render a list of reports. The last lines of both are as follows:
params.max = Math.min(params.max ? params.max.toInteger() : 15, 100)
render (view: 'list', model:[reportingInstanceList: reportingInstanceList, reportingInstanceTotal: i])
The list view is rendered as expected. At the footer of the list.gsp file I have:
<div class="paginateButtons">
<g:paginate controller="reporting" total="${reportingInstanceTotal}" max="25"/></div>
</div>
The list is working, the buttons for the pagination are there but it is always displayed the whole collection. Notice that I do not have files callled listdoiTln.gsp or listdoiEv.gsp. I am using list.gsp with different data models.
Surely I am doing something wrong.
Any hint?
Thanks in advance.
Luis
I had trouble with this, too, for quite a while. Try this:
Evaluate param.offset in the controller:
params.offset = params?.offset?.toInteger() ?: 0
Include the params in the model:
render (view: 'list',
model:[reportingInstanceList: reportingInstanceList,
reportingInstanceTotal: i,
params: params])
Check whether the value of reportingInstanceTotal is the value that you expect. That tripped me up for a while.
If it still doesn't work, let me know, or try looking at one of the list.gsp pages and its associated controller that are generated by the grails generate-all command.
The paginate buttons are quite cool, but there is little documentation and it takes longer than I expected to set them up.