Validate text field - InfoPath Dev
in

InfoPath Dev

Validate text field

Last post 12-08-2009 05:07 AM by Svetoslav. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 10-27-2008 03:55 PM

    Validate text field

    //<namespacesDefinition>
    XDocument.DOM.setProperty("SelectionNamespaces", 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:q="http://schemas.microsoft.com/office/infopath/2003/ado/queryFields" xmlns:d="http://schemas.microsoft.com/office/infopath/2003/ado/dataFields" xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-04-28T23:32:58" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003"');
    //</namespacesDefinition>

    function CTRL2::OnClick(eventObj)
    {
      var Enteredby = XDocument.DOM.selectSingleNode("/my:myFields/my:EnteredBy").text; (Error message appears here, saying object required)
     
      if (parseInt(Enteredby, 10) = ""){
       XDocument.UI.Alert("Invalid ID 2.  Please try again.");
       return
      }
    }

    How can I overcome this issue???

     

     

    Dave
  • 10-27-2008 09:07 PM In reply to

    Your

    var Enteredby = XDocument.DOM.selectSingleNode("/my:myFields/my:EnteredBy").text;

    line looks ok, but you will get that "object required" error if you reference a node that does not exist (e.g. it is in an optional section that is not included at the time) or if the XPath is misspelled, and that includes case.  Please make sure that the node is actually called EnteredBy and not enteredBy or Enteredby.

    There is definitely a problem with this line:

    if(parseInt(Enteredby, 10) = ""){

    if you want to compare two values you need to use the == operator, not =, but in this case, you should be using

    if(isNaN(parseInt(Enteredby, 10)){

    to check whether Enteredby is a valid number or not.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 10-29-2008 02:23 AM In reply to

    Hi,Use the following code.function CTRL2::OnClick(eventObj)
    {
    if (XDocument.DOM.selectSingleNode("/my:myFields/my:EnteredBy") != null){
      var Enteredby = XDocument.DOM.selectSingleNode("/my:myFields/my:EnteredBy").text;
     
      if (parseInt(Enteredby, 10) == '')
      {
               XDocument.UI.Alert("Invalid ID 2.  Please try again.");
               return
       }
     }
    }

     

    Swathip
    www.ggktech.com
  • 12-08-2009 05:07 AM In reply to

    Hi Jimmy,

     

    I have similar proble, I have a text field in a section which has some conditional formatting. Since the form is opened from another form, this field is automatically populated. But this action was introduced somehow later so in some of the forms the field is empty. It is very confusing because when the field is full or was full and I delete the information it works just perfect, but if the field hasnt contained any info, it showes me error object required. I am prety sure that the XPath is correct. I see no point in this problem. Do you have any idea where it can come from ?

     

    Regards,

    S. Z.

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