SetValue Blank for date type and double - InfoPath Dev
in

InfoPath Dev

SetValue Blank for date type and double

Last post 01-04-2012 10:35 PM by Jimmy. 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • 12-23-2011 07:19 AM

    SetValue Blank for date type and double

    I have a 2010 browser form (c#). some of the work in the form requires the fields values to be cleared. Is there an easy way to set a section of fields to blank? also I have to fields I can set to blank without IP bitting back

    Date field I have tried

    RateEffective.DeleteSelf();

    RateEffective.SetValue("");

    RateEffective.SetValue(null);

    RateEffective.SetValue(string.Empty);

    although the field is set to blank on most of these IP throws a validaton error on the field as if user enterend invalid data and the form will not save.

    Also have a similar issue on a number field set to double, currency. I was forced to set it to 0, but I would rahter have it blank.

     

    thanks and happy holidays

    Kind regards,
    Larry
    Filed under:
  • 12-23-2011 07:32 AM In reply to

    Re: SetValue Blank for date type and double

    nevermind, not really sure what I missed, but set both values to string.Empty and it's working.

     

    Thanks and enjoy

    Kind regards,
    Larry
  • 12-23-2011 07:38 AM In reply to

    Re: SetValue Blank for date type and double

    If the fields are set to allow blank values, then you will most likely get a validation error unless you re-add the xsi:nil attribute after setting them to blank.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 12-23-2011 10:26 AM In reply to

    Re: SetValue Blank for date type and double

    Thanks Jimmy. Would you mind sharing an easy way to do that? I know it would soething like

    @xsi:nill=true

    but I am not sure how to apply it.

    Kind regards,
    Larry
  • 12-23-2011 11:39 AM In reply to

    Re: SetValue Blank for date type and double

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 12-29-2011 07:05 AM In reply to

    Re: SetValue Blank for date type and double

    Sorry took so long to reply.

    Jimmy hope you have a great holiday.

    that worked perfectly, thanx

    Kind regards,
    Larry
  • 01-04-2012 12:00 PM In reply to

    Re: SetValue Blank for date type and double

    I am still hitting a wall. I have found that the client doesnt act the same as the borwser form. after some more research and what already has been provided I came up with this

    
    if (RateExpiration.HasAttributes) 
    {
    if (RateExpiration.GetAttribute("xsi", NamespaceManager.LookupNamespace("my")) == null)
    {
    RateExpiration.SetValue(
    string.Empty);
    RateExpiration.CreateAttribute(
    "xsi", "nil", NamespaceManager.LookupNamespace("xsi"), "true");
    }

    }

    else {
    RateExpiration.SetValue(
    string.Empty); RateExpiration.CreateAttribute("xsi", "nil", NamespaceManager.LookupNamespace("xsi"), "true");
    }

    When I test this in the client workes perfectly. When I run it in the browser the field (Date type) get a validation error. The red asterisk. I would like to put this to bed. any other suggestions?

    Kind regards,
    Larry
  • 01-04-2012 10:35 PM In reply to

    Re: SetValue Blank for date type and double

    Please try this instead of RateExpiration.SetValue(string.Empty);

                    if (RateExpiration.MoveToFirstChild())
                    {
                        RateExpiration.DeleteSelf();
                    }

    This will actually delete the text content instead of replacing it with blank text, which is a subtle difference in browser forms.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
Page 1 of 1 (8 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.