How to set minLength for PrimeFaces autocomplete - ajax

I have dialogbox which consists an autocomplete element and several other fields depending on it. What I want is to run completeMethod when autocomplete field is empty. However, this method executes only there is one or more character in the field. For instance, assume I typed 'x', then if I remove it, it should be called. I need to know if it is empty because I will change other fields according to it. I already tried minLength but it has no effect whatsoever
<p:autoComplete id="findCommand" value="ControllerClass.someObject
completeMethod="#{ControllerClass.completeCommand-returns objects-}/..>
<p:ajaxlistener="#{ControllerClass.onCommandChange} update="someotherfield"
event="itemSelect" /></p:autoComplete>
The completeCommand method won't be called if the field is empty. Here is what I tried:
1- I added an ajax tag with change and assigned some other method to it to control the field. But it
ruins itemSelect ajax, since it tries to assign query string to object when user types something, which is wrong.
2- I tried to use second answer, however since I can't figure out if field is empty, it has no use:
JSF access html element value in bean class

minQueryLength = "0" worked. Here is the link I've found this.
http://www.primefaces.org/docs/vdl/6.0/core/
You can select autocomplete from the left menu

Related

How do I have Primefaces focus not move to first field and yet show validation

I want to use <p:focus> in two ways:
1. Move to the input field if that field fails validation, i.e. is required
2. If on a page that has an input field that is visible when the page loads then move to that field. But if the page has a lot of introduction text and the input field is way down the page then don't move to the field as the user has to then scroll up to read the start of the page.
How can I have both cases handled? It seems that if I have <p:focus> I cannot avoid the page scrolling automatically way down the page if the first input field is there but I also want to move to the required field if a value has not been given.
Thanks
First, don't use the attribut for to select the default focused element.
Second, you only have to update your p:focus, and it will automatically select the first field where error occured.
For 1: See the answer above or http://www.primefaces.org/showcase/ui/misc/focus.xhtml
For 2: The only solution I know of that can achieve this is to not use the <p:focus/> and implement your own focus code (not to difficult). Detect the position of the first input and if it is far down, don't 'focus' it.

Issue with validation in knockout js

I put validation on name input field field you can see it when you click on addFields.I am having problem that validation message coming before click on Add Branch button because in addFields function i'm setting the value of name empty because if i don't do this click on edit and make changes and click add or cancel on it and after that click on addfields then it show the previous value in input fields. i want to show validation message on click of Add Branch and want input fields empty on click of addFields and with values on click of edit. How can i achieve these scenario together ?
here is link
`http://jsfiddle.net/sohimohit/43zkoszu/13/`
You can use showAllMessages(false) on your error object
http://jsfiddle.net/43zkoszu/16/
All though I must say that your method of doing this is a little strange. Normaly with MVVM you have a seperate model for this and create a new one each time you want to registger a new
As #Marius has already said, you need use isModifed(false) for changed field. So, your code should be like this
self.AddField = function(){
self.BranchId("");
self.BranchId.isModified(false);
self.name("");
self.name.isModified(false);
self.description("");
self.description.isModified(false);
// .... etc ..
self.show(false);
self.show.isModified(false);
self.showFields(true);
self.showFields.isModified(false);
}
Also, please, notice you have comas (,) instead of semicolons (;) in your AddField code.

jQuery validate on cloned form fieldsets works but is ignored by .valid() method on the form element

I'm sure this has come up many, many times before but I am at my wit's end with this problem. I'll try and be as descriptive as possible without bloating the problem statement.
I am using the jQuery validate plugin for form validation. All form rules and messages are retrieved via ajax and then initialised. All form validation works like a charm until I start cloning fieldsets inside the form to give the user the ability to add additional entries.
The input fields react exactly as they should to changing values (error highlights and displaying messages etc), but when I call the .valid() method on the form it ignores the additional fieldset cloned from the first.
I have added test rules after cloning the fieldset, and again, the input field responds correctly to the newly assigned rule but gets ignored when calling .valid() on the form element.
I will add code snippets should anyone be willing to help me find the problem.
Thanks in advance!
Fred
Edit:
I have found that the .valid() method only uses the first fieldset in the form. Take note that all input names of cloned fieldsets are the same as the original. For example, say i have a field called productName in my original fieldset and i clone it, I will now have two inputs in the form with the same name attribute.
Could it be that jQuery validate only cares about the first instance it reaches and validates on that? I have seen posts about jQuery validate not playing nice with duplicate input names on forms but i believe it was resolved.

YUI DataTable Changing DraggableColumn and Resizable

After a YUI2 datatable is constructed, is it possible to change configuration settings dynamically?
If draggableColumns was not set true when the datatable was initialized, how can I change that behavior later on?
Similarly, when columns are not identifed as resizable, is there a way to change it later?
I expected a datatable method would allow this to happen (set on/off), but I can't seem to find something like that in the API (http://developer.yahoo.com/yui/docs/module_datatable.html).
So, I tried browsing the datatable object and changing each column's 'draggable' flag. That didn't work and it also didn't seem the right way to do it.
How can I do this?
Every element's configuration object can be accessed via it's cfg attribute.
So, in order to set draggableColumns config property dynamically, you need to use :
myDatatable.cfg.setProperty("draggableColumns", "true", true)
Note that the second boolean argument should be a string. Refer this link for reference.

How do you switch backing bean objects in JSF?

Suppose I several tags, text input, radios, etc referencing one instance object. I would like to use a dropdown on that page to switch the references mentioned before to another instance of the object.
This part is pretty easy with change listener. However, the problem I have is the values currently displayed on the screen are getting set into the new, second instance.
I would like the current values to be stored in the current instance, and then the when the page refreshes I would like the new values to come from the new instance and be displayed on the screen.
Is there was way to do this? Does my question make any sense?
Grae
A value change listener is exactly the wrong tool for this, because it gets called before the values are set.
What you want is an action listener, which will get call after the values from the page are validated and set.

Resources