SharePoint: Extended DVWP-Part 2: Fill in the default value for the Insert template for multiple DVWP

Source: Internet
Author: User
Document directory
  • ID-entifying Solution
  • Set the default value for the second layer of the cascade drop-down box
  • Smell delicious desserts

Last time, we discussed how to use jQuery to set a default value for the control. In this example, we set a value for a SPCascadeDropdowns drop-down box that uses Marc Anderson. This is a very simple step. You only need to process the items in the browser you are using and the/or drop-down list box.

However, when we use the Easy Tabs of javase Humbert in the project, a page can have multiple DVWP, each of which is a tab. And these DVWP are basically the same, but different filters are used. This means that no matter which tab you are on, all form fields are in the same layout mode.

Therefore, if we use the script in the previous article, each Insert template on the page (for our example, there are several DVWP actually there are several Insert templates) will be set with the same default value. However, for most scenarios with multiple DVWP, this is not our result.


How should we differentiate them?

ID-entifying Solution

The simplest selector in jQuery is the ID selector ("# id "). To limit the range for setting the default value, we only need to specify a unique ID for each form, and then obtain it when we assign a value.

1. In the design pane of SharePoint Designer (SPD), click the leftmost column of the title row.


Click "Employee" in the row of the title, and the code pane will highlight "deep dive. headerfield". In this way, you can locate the top table of the form.

2. In the highlighted area, the table tag pointed by the arrow includes the entire display area, including editing, deleting, and inserting templates. This is where we will add the ID

<table border="0" width="100%" cellpadding="2" cellspacing="0" id="FTE"></table>

Next we can export the entire WebPart for reuse. We need to add it to every page created for the manager and set the filter conditions so that it can see what the manager cares about. Therefore, it is best to give this table a general description ID. To put two similar DVWP values on the same page, we can provide a more descriptive unique ID for the table in each DVWP, then the ID is related to the page where it is located.
3. process the remaining DVWP on the page in the same way, so that each has a unique ID.

For the preceding tab set, I used these IDs: ACB_FTE, ARC_FTE, ADC_FTE, PRN, and Other. The first three are the same DVWP imported three times, each corresponding to a Location. For each of the three, I set a filter to specify a specific location, and edit its ID to identify the location where it is being processed.

Now, let's return to jQuery and start setting the default value.

    $(document).ready(function() {        $("select[title=Location]").val("ACB");        $("input[title=Location]").val("ACB").next("img").trigger("click");        $().SPServices.SPCascadeDropdowns({            relationshipWebURL: "/operations",            relationshipList: "LocGroup",            relationshipListParentColumn: "LocDept",            relationshipListChildColumn: "Group12",            relationshipListSortColumn: "Group12",            parentColumn: "Location",            childColumn: "Group"        });        .        .        .    });</script>

 

To make. val () specific to DVWP, we will add the jQuery ID selector before:

$("#FTE select[title=Location]").val("ACB");$("#FTE input[title=Location]").val("ACB").next("img").trigger("click");

For me, I also need to copy these two lines of code for another DVWP on the page:

$("#ACB_FTE select[title=Location]").val("ACB");$("#ACB_FTE input[title=Location]").val("ACB").next("img").trigger("click");$("#ARC_FTE select[title=Location]").val("ARC");$("#ARC_FTE input[title=Location]").val("ARC").next("img").trigger("click");$("#ADC_FTE select[title=Location]").val("ADC");$("#ADC_FTE input[title=Location]").val("ADC").next("img").trigger("click");$("#PRN select[title=Location]").val("PRN");$("#PRN input[title=Location]").val("PRN").next("img").trigger("click");

Note the jQuery running method.: The above script does not mean "finding a specific variable and setting its value ". In this way, if the variable is not defined, an error will occur. Instead, it means: "set its value for each object matching the selector ." If it does not find anything, it is harmless and smelly, and the code just moves to the next statement.

Similarly, the following SPServices. SPCascadeDropdowns () call will also be executed in each drop-down box found by name, so it is also for all DVWP on the given page. Because the control to be operated has the same name, we only need to include a coordinated call in the. ready () function.

Note that multiple Insert templates (or edit templates) can be opened on multiple tabs at the same time, even though we can only see one at a time, but it can all be in the open state.When multiple sets of drop-down boxes are opened, cascade operations cannot work.Even if you do not click Save or cancel, you can open another tab to insert or edit a template. But once you encounter this problem, you should know why.

Set the default value for the second layer of the cascade drop-down box

In the above, you may have noticed two things:

1. I didn't show you the Other Tab
2. The PRN tab sets the value of the second-level drop-down box.

First, I don't set the Other tab on the top because I don't know what it will be .. However, I set the default value for the second layer.

In the second place, for PRN, I know that there are actually PRN employees in three locations, so I set the second layer as one of the locations.

So, how to set the second layer?

No surprise, just like the method at the first layer.

$("#PRN select[title=Group]").val("ACB");$("#PRN input[title=Group]").val("ACB").next("img").trigger("click");$("#Other select[title=Group]").val("ACB");$("#Other input[title=Group]").val("ACB").next("img").trigger("click");

 

On the Other tab, I set Group instead of Location. When you select the "other" location, the Group will not change. In other words, if the user chooses a "non-Other" {detour, heh} location, the Group will be empty.

I put the second layer after calling the first layer SPCascadeDropdowns. However, the Other tab raises some issues:

"If I set the default value for all fields, is it necessary to set the second layer ?"
No, you can set it before calling SPCascadeDropdowns.

"What will happen if I only set Layer 2 ?"
It does not matter. The SPCascadeDropdowns cascade function is bound to the onChange () event in the drop-down box. After the page is loaded, the cascade event does not actually occur, and then changes in the parent drop-down box.

Smell delicious desserts

We are close to the final stage of extending the DVWP series. Next time, we will summarize the total number and category.

 

References

SharePoint: Extending the DVWP-Part 32: Filling in Default Data on the insert Template with Multiple DVWPs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.