1

I'm trying to disable a panel on my xPage with CSJS.. but neither method works:

dojo.byId("#{id:panel1}").readonly=true;
dojo.attr("#{id:panel1}", "readonly", "true");
document.getElementById("#{id:panel1}").setAttribute("readonly", "true");

1 Answer 1

0

Set .attr('disabled', 'disabled'); for all input elements within your panel.

<?xml version="1.0" encoding="UTF-8"?>
<xp:view
    xmlns:xp="http://www.ibm.com/xsp/core">
    <xp:panel
        id="panel1">
        <xp:inputText
            id="inputText1"
            value="#{sessionScope.Test}"></xp:inputText>
    </xp:panel>
    <xp:br></xp:br>
    <xp:button
        value="Disable Input Field On Client Side"
        id="button1">
    <xp:eventHandler
        event="onclick"
        submit="false">
        <xp:this.script><![CDATA[
            var panel1 = document.getElementById("#{id:panel1}");
            dojo.query('input', panel1).attr('disabled', 'disabled');
        ]]></xp:this.script>
    </xp:eventHandler></xp:button>
</xp:view>

dojo.query('input', panel1) returns a collection of all input elements within panel1.

.attr(...) sets the attribute to every collection's element.

If you want to disable other elements within the panel too just add the element's type to the query, for example dojo.query('input, button', panel1) for buttons.

7
  • I'm getting this error TypeError: dojo.byId(...).attr is not a function.... or... TypeError: document.getElementById(...).attr is not a function
    – John Glabb
    Aug 16, 2016 at 18:23
  • I added an example XPage to show how to set .attr('disabled', 'disabled') Aug 16, 2016 at 18:36
  • is there a way to set really read-only property instead of disabled? I need to read input components value after that
    – John Glabb
    Aug 16, 2016 at 20:00
  • Yes, you can use readonly instead of disabled the same way: .attr('readonly', 'readonly') or .attr('readonly', true). Aug 16, 2016 at 20:04
  • 1
    that explains. Thank you very much Mr. Knut
    – John Glabb
    Aug 16, 2016 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.