Default value in field contained in repeating section

P

Paulo

Hello everybody,

As the subject says, I have a repeating section with several fields. The
users are able to add/remove them. Whenever they add one, I want a field in
the added section to get a random value.

At first I wanted to use the default value feature of the field. But I am
not able to specify my own function...

So I started to look at the onvalidate event, but the site method returns a
read-only object so that I'm not able to change it....

I am sure this is pretty easy, but could one help me?

Thanks, Paulo
 
S

S.Y.M. Wong-A-Ton

Did you also try the OnAfterChange event? The DOM is writable in the
OnAfterChnage.
 
P

Paulo

Hello,

Thanks for your response.
Well, then there is something I am missing.
Onvalidate, onafterchange, onbeforechange all have DataDOMEvent object as a
parameter. Thus Object has several properties including one that is the site
property which enables me to know which of the repeating node generated the
event. I want then to change that particular node's value. But the site
method is readonly. If I use the XDocument property of the DataDOMEvent, how
will I be able to know which of my repeating fields just generated the event?

What am I missing?
Thanks
 
P

Paulo

Hello,

Again, thanks for your help. I had a look at your code and I was pretty
convinced it would work but it didn't..
So here is what I did:
<Section>
<SectionID/>
<Question>
<QuestionID/>
</Question>
</Section>
I added an Onafterchange event to QuestioID for example.
BTW: Section and Question are repeatable sections..
Question is a whole integer
The code looks like this:

function msoxd_my_QuestionID(eventObj) {
// First I tried another approach
eventObj.Site.removeAttribute("xsi:nil");
//I was hoping this is the right object since when I call
eventObj.Site.nodeName I get the right element name
eventObj.Site.text = 1111;
}

It tells me:
Text is not allowed in the context of element .... acording to DTD/Schema...


ok so I tried another method.. the one described on your pages which I think
is quite the same.
I think I extracted was is relevant for what I wanted to do

function msoxd_my_QuestionID(eventObj) {
var xmlNil = eventObj.Site.ownerDocument.createNode(2,"xsi:nil",
"http://www.w3.org/2001/XMLSchema-instance");

xmlNil = "true";
eventObj.Site.text='';
eventObj.Site.setAttribute(xmlNil);
// change the value here...
}

When I do this I can into a recursion loop...

I still am not able to do it :(
Paulo
 
S

S.Y.M. Wong-A-Ton

I'm not sure what you're trying to do, Paulo. I tried your first method and
it worked fine for me. I put a repeating table in a repeating section and
tried to programmatically write to a field (Whole Number) in the repeating
table (QuestionID) in your case, and it worked. The code that I added to the
OnAfterChange of the field was:

if (eventObj.Site != eventObj.Parent)
{
eventObj.Site.removeAttribute("xsi:nil");
eventObj.Site.text = 2;
}

How did you set up your form? It sounds like you are trying to do something
that is not allowed by the schema of the form.

You may want to read this article too:
http://msdn.microsoft.com/library/e...DoubleNotifications_HV01083591.asp?frame=true.
 
P

Paulo

Hello,
I'm not sure what you're trying to do, Paulo. I tried your first method and
it worked fine for me. I put a repeating table in a repeating section and
tried to programmatically write to a field (Whole Number) in the repeating
table (QuestionID) in your case, and it worked. The code that I added to the
OnAfterChange of the field was:

And you attached this to the QuestionID field...right?
if (eventObj.Site != eventObj.Parent)
{
eventObj.Site.removeAttribute("xsi:nil");
eventObj.Site.text = 2;
}

How did you set up your form? It sounds like you are trying to do something
that is not allowed by the schema of the form.

Euh, what do you mean?:).
I added the fields one after the other...
Hm how do I debug this Schema violation?

Paulo
 
P

Paulo

Hello again,

I think I got it!
Stupid!
For my tests I always perfomed a Preview Form.....
But when I close it and fill it out, then it works..... :)

I need additional tests but I think that's it!
Thanks for your help!!!
Paulo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top