How do you disable an autocomplete fields programmatically?

How do you disable an autocomplete field programmatically?

I’ve tried:

$(“jsfwmp8809:defaultForm:AOI”).disabled = true;

$(“jsfwmp8809:defaultForm:AOI”).autocomplete = “off”;

CAF.Model(“jsfwmp8809:defaultForm:AOI”).SetDisabled(true);

None of these work. Am I left with the only option is to hide this control and display a simple text field in its place?

The prototypejs way to set an attribute on an element is documented at [1].

  1. http://api.prototypejs.org/dom/Element/prototype/writeAttribute/

Which equates to something like this:

$("jsfwmp8809:defaultForm:AOI").writeAttribute("disabled", "true");

$("jsfwmp8809:defaultForm:AOI").writeAttribute("autocomplete", "off");

Or via the CAF model:

CAF.model("jsfwmp8809:defaultForm:AOI").setDisabled(true); 

That works. I thought I’d tried that.

Now that its disabled when I submit the form the validation kicks off. How do I stop that?

I assume you mean that no validation happens on the disabled field?

Generally, disabled fields aren’t validated or sent to the server.

If you want the field to not be editable but still be validated and submitted, you probably want to set it as readonly instead of disabled.

For example:

$("jsfwmp8809:defaultForm:AOI").writeAttribute("readonly", "true");  

Is there a CAF.model method to do that?

No, since it would be duplicating logic already provided by others.

Thanks Eric that helps a lot.