Validation and views

R

Ruky Obahor

I have an infopath form with three views

1 - staff view
2 - managers view
3 - print view
The managers view has an additional section for managers to approve the form
before submitting. the fields on these section are mandatory.

The problem is that when staff fill in the staff view and try to submit the
form, they get validation error saying that the form cannot be submitted cos
some of the fields in the managers view have not been filled out.

how do i resolve these cos these fields arent in the staff view and only
managers are to meant to fill them fromthe managers view

please can some one help
 
S

Scott L. Heim [MSFT]

Hi,

One way you could do this would be to remove the attribute of being
"required" and then implement a custom method (i.e. a button) to do the
submit so you could programmatically check to insure the "required" fields
are indeed completed.

In this manner, you can verify the View that is active and then insure the
appropriate fields are not blank.

Best regards,

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 
R

Ruky Obahor

Thanks for you help with this.

I have two buttons on the form. the first one is on the staff view which
submits to the manager and the second one is on the managers view which
submits to sharepoint.

I am not good at programming so can you please explain how i can implement a
custom method (i.e. a button) to do the submit so I can programmatically
check to insure the "required" fields are completed?
 
S

Scott L. Heim [MSFT]

Hi,

Without having some knowledge of programming this could be a bit difficult;
however, here is some sample code:

- On a button on my first View, I have the following:

var strCurrentView = XDocument.View.Name;
if(strCurrentView == "View 1")
{
var objView1Field =
XDocument.DOM.selectSingleNode("//my:myFields/my:txtView1")
if(objView1Field.text == "")
{
XDocument.UI.Alert("txtView1 field must be filled in!");
}
else
{
var objMailAdapter = XDocument.DataAdapters("EmailSubmit");
objMailAdapter.Submit();
}
}

- On a button on my second View, I have this code:

var strCurrentView = XDocument.View.Name;
if(strCurrentView == "View 2")
{
var objView1Field =
XDocument.DOM.selectSingleNode("//my:myFields/my:field2")
if(objView1Field.text == "")
{
XDocument.UI.Alert("field2 field must be filled in!");
}
else
{
var objSubmitAdapter = XDocument.DataAdapters("Main submit");
objSubmitAdapter.Submit();
}
}

When I designed my sample, I added 2 data connections: one for a "e-mail"
submit and one for a "Sharepoint" submit. So depending on the current view,
I check to see if the text box is blank and if not, submit to the
appropriate "connection." If you have numerous fields that need to be
checked for completion, you would need to add those in the same manner as I
have shown above.

This code could be streamlined but hopefully this will give you an idea of
how this works.

I hope this helps!

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 
R

Ruky Obahor

Thanks once again and sorry to bother you.
i need to get this right.
Are you saying that i should
click on the button on the any of the views
and then under action select rules and custome code
and then click on the edit form code
and use the appropriate code you have sent me. (I know i need to ammend code
to fit my form). if this is not current, where do i paste the code.

Thanks

Ruky
 
S

Scott L. Heim [MSFT]

Hi Ruky,

That is correct:

- Open the form in Design View
- Right-click on the button and choose Properties
- Click the Edit Form Code button and what you will initially see is
something like this:

function CTRL2_5::OnClick(eventObj)
{
// Write your code here
}

- Add the sample code I sent you between the braces ("{ }") above.

Best regards,

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 

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