set input field readonly

Hi,

I’m initializing my dhxForm from Object and would like to set some input fields as readonly.
Is there any possibility?

Or could you please advise me how to modify dhtmlxfrom.js ?!

Thanks a lot!

Hello,

Please see attached demo.
48.zip (27.1 KB)

It works fine! Thank you very much.
It was also possible to integrate a new function in dhtmlxform.js.

kind regards

Try the same example but loading data from a xml.

[code] function doOnLoad() {

        var formData = [
            {type: "input", name: "myInp1", label: "Read-only item", value: "Some text"},
            {type: "input", name: "myInp2", label: "Read-write item", value: "Change me!"},
            {type: "button", name: "myButton", value: "Submit"}

        ];
        form = new dhtmlXForm("listObj", formData);
        form.loadStruct("xml/detalle_medios_1.xml");
        //original code
    form.doWithItem("myInp1", "setReadOnly", true);
        //added code
		form.doWithItem("ID", "setReadOnly", true);
[/code]

xml/detalle_medios_1.xml:

<items>
<item type="label" label="Campos Fijos" />
<item type="input" name="ID" bind="ID" label="Registro"  />
</items>

It’s draw the form correctly, but did n’t add readonly property to Input “ID”. Why?

Please try to call form.doWithItem() after form init, using loadStruct() form send async request to server.

You need:

form.loadStruct("xml", function(){
    form.doWithItem(...);
});
// or
form.attachEvent("onXLE", function(){
    form.doWithItem(...);
});
form.loadStruct("xml");

Excelent ANDREI!!! :astonished: .

After hours trying finally i saw my mistake: The new funtion

dhtmlXForm.prototype.items.input.setReadOnly = function(item, state) {
   var inp = item.childNodes[0].childNodes[1].childNodes[0];
   if (state == true) inp.setAttribute("readonly", true); else inp.removeAttribute("readonly");

was not on the right place. I puted inside body & it’s works :smiley: THANKS A LOT.

Now i have the same problem using the type: “select” how can i buld the function to make the select’s type readonly. :unamused:

Best

It works correctly?
on safari, works fine. but on IE8,could not change a readOnly attribute.
input field is staying with read/write attribute.
any other solution?

Hello,

  1. How do you think readonly for select should work? It not allow to edit options’ text byt the default (or you mean change options?)
  2. In form 3.0 you can set readonly attribute for input in json.
  1. How do you think readonly for select should work? It not allow to edit options’ text byt the default (or you mean change options?)
    –> My question is only about input field problem.
  2. In form 3.0 you can set readonly attribute for input in json.
    –> 3.0b tested. but xml structure not supported. I found this rule.
    --> it doesn’t works.
    {type: “input”, label: “Login”, value: “p_rossi”, readonly : “true”}, --> works correctly.

I prefer a xml to a json.
when you release a product version, two functions expected.
One is readonly input field in xml structure.
The other is text item type(it contains only text with a bind)

Thanks regards.

Hello,

  1. Check attachment for:
    → it doesn’t works.
    (v 3.0)

  2. The other is text item type(it contains only text with a bind)
    explain please?
    dhtmlxform.js.zip (14.4 KB)