Disable textbox from code - InfoPath Dev
in

InfoPath Dev

Disable textbox from code

Last post 06-23-2007 04:15 AM by saudak. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 06-16-2007 12:18 AM

    Disable textbox from code

    I have 2 radio buttons, on the selection of either, I need to enable or disable textboxes from script (I use VBscript)

     Below, Select is a optionbutton with text valoes of 'Old' and 'New'

    Old and New Are 2 textboxes

    But this code is NOT WORKING

    Sub msoxd_my_Select_OnAfterChange(eventObj)

    if XDocument.DOM.selectSingleNode("/my:myFields/my:Select").text = "Old" then

        XDocument.DOM.selectSingleNode("/my:myFields/my:Old").Enabled = True

        XDocument.DOM.selectSingleNode("/my:myFields/my:New").Enabled = False

    End if

    if XDocument.DOM.selectSingleNode("/my:myFields/my:Select").text = "New" then

        XDocument.DOM.selectSingleNode("/my:myFields/my:New").Enabled = True

        XDocument.DOM.selectSingleNode("/my:myFields/my:Old").Enabled = False

    End if

    end sub 

    Please tell me how do I do this :- XDocument.DOM.selectSingleNode("/my:myFields/my:New").Enabled = True

  • 06-18-2007 09:37 AM In reply to

    Re: Disable textbox from code

    Hello saudak,

    You cannot manipulate the form controls in the code - the only thing you can access is the XML data. As such , selectSingleNode returns you an XML node, you can only change its value and you can never communicate directly with the control that displays that value. Because of this, there is simply no Enabled property available on the XML DOM node.

    The correct way to achieve the functionality you require is to use conditional formatting in the view and then use code to change the condition that affects the formatting:

    1. Add an extra node (say field1) to the data source that determines whether or not your target control is enabled or disabled (this node will only exist in the data source... if you want to keep it clean it's better to put in into an aux-dom but this is more advanced)

    2. Add conditional formatting to your textbox saying that whenever field1 is, for example, 1 then your textbox is set to read-only (note that you cannot disable a textbox, you can only set it to read-only or hidden).

    3. In your code, set the value of field1 to 1 or 0 depending on what you need

    Good luck with this!

    Dave.

    David Airapetyan / Software Services Architect
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 06-18-2007 11:53 PM In reply to

    Re: Disable textbox from code

    Hi dave,

    Thanx for the reply and the Idea,

    I will try it ASAP, But how do you make a textbox readonly, can I do it from InfoPath or should I write code?

  • 06-19-2007 08:50 AM In reply to

    Re: Disable textbox from code

    Hey saudak,

    to make a textbox read-only, double-click on it, select Display then Conditional Formatting.

    Add your condition, then check the read-only box.

    Your condition may depend on another field. Now you can set this field either via rules, calculation or code, it's up to you!

    This is the only way of dynamically changing the read-only property, via the conditional formatting mechanism. You cannot change control properties via code because controls are not exposed to code, only data is.

    David Airapetyan / Software Services Architect
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 06-23-2007 04:15 AM In reply to

    Re: Disable textbox from code

    Thanx Dave !

    Im a web programmer, I always think the 'code' way,

    thanx again 

Page 1 of 1 (5 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.