Quantcast
Channel: SharePoint Forms Designer
Viewing all 36 articles
Browse latest View live

How to conditionally hide, disable, and make mandatory fields on SharePoint forms dynamically

$
0
0

Here I'd like to demonstrate the most popular cases you may face during implementation of SharePoint forms with complex logic. Most likely you will need to combine the cases described below to cover your requirements but it's quite easy if you have enough samples. To accomplish the tasks below I used SharePoint Forms Designer 2.8.10. All samples work properly for all editions of SharePoint 2010/2013 including Foundations and Office 365.

First of all, I'd like to make an important notice which is common for all the cases. fd.field() method of JavaScript framework expects an internal name of a field you want to retrieve. As you might know, it's not easy enough to obtain an internal name of a field in SharePoint, so we included this property into field properties in Forms Designer 2.8.10:

Internal name of SharePoint field

Now you can just copy and paste it into your code in a much simpler way even without closing Forms Designer. OK, let me start.

Prepopulate field and disable/enable it based on condition

Let's say we have a task form and we need to set the Percent Complete to 100% and disable it when the user turns the Status field into Completed:

SharePoint conditional fields

We should place the following code into JS-editor of Forms Designer:


function setPercentComplete() {
if (fd.field('Status').value() == 'Completed') {
// Setting the Percent Complete to 100
fd.field('PercentComplete').value('100');

// Getting JQuery-object of the field and disable it
fd.field('PercentComplete').readonly(true);
} else {
// Getting JQuery-object of the field and enable it
fd.field('PercentComplete').readonly(false);
}
}

// Calling setPercentComplete when the user changes the status
fd.field('Status').change(setPercentComplete);

// Calling setPercentComplete on form loading
setPercentComplete();

// Enabling fields before the submission
fd.onsubmit(function () {
fd.field('PercentComplete').readonly(false);
return true;
});

Please, pay attention to the last part of the code:


// Enabling fields before the submission
fd.onsubmit(function () {
fd.field('PercentComplete').readonly(false);
return true;
});

Most browsers don’t send values of disabled fields to the server during the submission, so they will be lost. Therefore, we need to enable all fields that we need to save right before the submission in onsubmit handler.

Hide/show field or set of fields conditionally

Now I will modify the script from the previous section so that it will hide the Percent Complete field. First, we should assign a CSS-class to the field to use it in JQuery-selector:

Assign CSS-class to SharePoint field

OK, now we can use it to retrieve the field container by the following way: $('.percent-complete'). Here is the modified code:


function setPercentComplete() {
if (fd.field('Status').value() == 'Completed') {
// Setting the Percent Complete to 100
fd.field('PercentComplete').value('100');

// Getting JQuery-object of the field container and hide it
$('.percent-complete').hide();
} else {
// Getting JQuery-object of the field container and show it
$('.percent-complete').show();
}
}

// Calling setPercentComplete when the user changes the status.
fd.field('Status').change(setPercentComplete);

// Calling setPercentComplete on form loading
setPercentComplete();

Please, notice that I've removed the last part from the code because values of hidden fields are passed to the server properly.

What if we need to hide multiple fields? There are several approaches. You can either put them into a single table and assign CSS-class to the table:

Assign CSS-class to multiple SharePoint fields

Next, use that class in JQuery-selector to retrieve the table and hide or show it:


// Hide the table
$('.fields-to-hide').hide();

// Show the table
$('.fields-to-hide').show();

Or if your fields are scattered about the form and you cannot put them into a single table, you can assign the same CSS-class to all fields that you need to hide e.g. 'field-to-hide' and use it in the selector to make all of them disappear:


$('.field-to-hide').hide();

Require field based on condition

At this section I'd like to demonstrate how to make some fields mandatory based on other field values. Let's go back to the original task form and say that we need to make the Due Date field required if the task is assigned to someone (the Assigned To field is not empty).

Here is the sample:


function setRequiredFields() {
if (fd.field('AssignedTo').value().dictionaryEntries.length != 0) {
// Add asterisks
fd.field('DueDate').titleRequired(true);
} else {
// Remove asterisks
fd.field('DueDate').titleRequired(false);
}
}

// Calling setRequiredFields when the user changes the assignment
fd.field('AssignedTo').change(setRequiredFields);

// Calling setRequiredFields on form loading
setRequiredFields();

// Custom validation
fd.onsubmit(function () {
if (fd.field('AssignedTo').value().dictionaryEntries.length != 0) {
if (!fd.field('DueDate').value()) {
alert('Please, fill in the Due Date field.');
return false;
}
}

return true;
});

As you can see, I've added the custom validation into onsubmit handler, whereas fd.field().titleRequired() just adds or removes the asterisk near the title.

Get values on display forms

Finally, I'd like to focus your attention on differences between display and edit or new forms. Display forms don't contain controls, so you can retrieve only the text representation of field values like you see them on a form. The samples above work on new and edit forms only. You should use the following syntax to obtain a text representation of values on a display form:


fd.field('Status').control()._el().text()

Get information on how to get or set values of different types of fields from the following article: http://formsdesigner.blogspot.com/2013/04/getting-and-setting-sharepoint-form.html

Please, feel free to ask your questions in comments.


Capture signature or hand-written notes in SharePoint form using tablets or mouse.

$
0
0

In this article I will describe the implementation of two business cases which require capturing hand-written marks and a signature in a form. I will use SharePoint Forms Designer 2.8.12 where Ink Sketch control appeared. With the help of this control you can save a hand-written note created with a tablet, a cell phone, or a mouse to a SharePoint 'Multiple lines of text' field with picked 'Plain text' option:

SharePoint 'Multiple lines of text' field with picked 'Plain text' option

It supports all editions of SharePoint 2010/2013 and SharePoint Online in Office 365.

Review of end-of-course questionnaire

The first scenario relates to a training process that ends with questionnaires which have to be filled in by trainees and verified by a trainer. We will simplify the verification process by providing a trainer with the touch interface allowing them to leave marks and notes by using iPad, a cell phone or another touch screen device. The result form for trainers will have the following view:

SharePoint questionnaire form with hand-written marks

First, we should create a form for questionnaire and design different views for students and trainers. I will split them into separate SharePoint groups and create different forms for these groups in Forms Designer. Forms Designer for Office 365 doesn't support groups functionality, so you should modify the result form with the help of JavaScript based on the current user. The first group, students, will be able to edit all fields except the score. The second group, trainers, will be able to score a student and leave marks and notes near each answer. We have to create a number of text fields to save trainer's notes in accordance with the number of Ink Sketch controls on a form. In our case we will use a separate Ink Sketch control for each student's answer, so we need to create the same number of text fields as the number of questions in the questionnaire.

Notice: fields for storing sketches must have 'Multiple lines of text' type with picked 'Plain text' option. You must select the field where you're going to store the sketch in the Ink Sketch properties in Forms Designer.

Here is the first form designed for trainees:

SharePoint questionnaire form for trainees

Here is the form designed for trainers:

SharePoint questionnaire form for trainers with hand-written notes

As you can see I turned all fields into read-only mode and put Ink Sketch controls near each field to allow trainers to make a separate note for each answer. Also the form for trainers contains the score field in edit mode.

Invoice with signature

The second scenario covers creating an invoice form with signature. As previously, we should create a text field to store the signature. Here you can see my invoice form:

SharePoint form with signature

I used the Related items control to display product items and the Ink Sketch control to capture the signature. Quite easy isn't it? You can use Forms Designer in conjunction with Workflow Actions Pack to create an invoice in PDF format with the signature and send it to your customer or accounting department by e-mail.

SharePoint 2010 and HTML 5

By default, Internet Explorer opens SharePoint 2010 pages in IE 8 document mode but IE 8 doesn't support HTML 5. So the Ink Sketch control uses flash component to provide the capability of drawing on a form. This component is quite slow and requires Adobe Flash Player. But you can switch the Ink Sketch control to HTML 5 mode by modifying your master page. Open it in SharePoint Designer and replace the following line of code:

<meta http-equiv="X-UA-Compatible" content="IE=8"/>

With this one:

<meta http-equiv="X-UA-Compatible" content="IE=Edge"/>

Save the master page and check in. Now all pages will work in the highest mode of Internet Explorer available.

Conclusion

The visual data is saved into SharePoint text fields as base64 string, so you can use it in Render Text Template workflow action of Plumsail Actions Pack to prepare an HTML-page and generate a PDF-file based on it with a signature and other notes created by a user directly on a form. To inject a note into HTML-template you should use the following syntax:

<img src="${{Signature}}" />

In the code above 'Signature' is the internal name of a 'Multiple lines of text' field containing the signature.

Filter related items by almost any field of SharePoint form

$
0
0

In this article I'd like to introduce you to a new feature of SharePoint Forms Designer 2.9.1 allowing to filter the Related items control by almost any form field including lookup, single line of text, number, choice, date, user, and even calculated column. First, I want to demonstrate the most common case, filtering by a lookup column.

Filtering by Lookup column

I've created a list of projects and a related list of issues. The Issues list contains a lookup column to the Projects list. Now I will show how to create a form for the Projects list with the list of related issues in it. We need to put the Related items control onto the project form and configure its data source following way:

Filter related items by lookup column on SharePoint form

Project column of the source list is a lookup to the Projects list. Here is the result:

Filter related items by lookup column on SharePoint form

As you might noticed I've configured filtering by a display column of the lookup column. But if you say have multiple projects with the same title you will see issues of all such projects in the same form. To avoid this you should add ID of the parent list as an additional column in the lookup settings:

Additional lookup field

Now you can filter the related issues by ID of the parent item in the Data Source Editor:

Filter related items by lookup ID column on SharePoint form

Filtering by Date column

Ok, now let's configure filtering by a date column. I've created Daily Reports list to store forms with the list of solved issues filtered by a date specified in the report. As previously, we need to place the Related items control onto the form in Forms Designer and configure its data source following way:

Filter related items by date column on SharePoint form

DateCompleted is a field of the Issues list containing resolution date of an issue. Here is the result:

Filter related items by date column on SharePoint form

Filtering by User column

And finally, I'd like to demonstrate how to filter the Related items control by a people picker field. For this case I've created User Reports list containing a people picker field. Next, we need to design a form with the Related items control linked to the Issues list and filtered by the people picker column:

Filter related items by user column on SharePoint form

Almost done. But in contrast to the previous cases we have to do additional stuff here because SharePoint returns people picker value as a link. So we need to extract plain username from the link and pass it outside the form to filter the related items properly. Put HTML-control onto your form, switch CDATA property to False and insert the following code into Content property:


<xsl:variable name="UserName" select="substring-after(substring-before(substring-after(@User,'userdisp.aspx?ID='),'&lt;'),'&gt;')"/>
<xsl:comment>
<xsl:value-of select="ddwrt:GenFireConnection(concat('*', '@User=', ddwrt:ConnEncode(string($UserName))), '')" />
</xsl:comment>

Please, pay attention that to make this sample working you have to replace the highlighted attributes with the internal name of your people picker field (Form field). Here is the report:

Filter related items by user column on SharePoint form

Summary

In this article I demonstrated how to filter related items by almost any field of the parent form. Please, note that if you need to filter related items by multiple columns, you can concatenate them into a single calculated field and configure filtering by this column. Feel free to ask your questions in the comments.

Designing custom forms for smartphones, tablet devices, and regular PCs

$
0
0

Today we’d like to introduce you our new Forms Designer 3.0.1 feature for building custom forms for various types of devices, be it mobile phones, tablets or regular PCs. For all these types you can now create separate Display, New and Edit forms which enables you to customize the way different devices view your website. Let’s take a look at a use case.

Say we have a form that looks like this:

SharePoint form for PC

Navigating such form on a mobile device would be pretty cumbersome, as you can imagine. What we need to come up with is something that looks more like this:

SharePoint form for mobile device

How can we achieve this? The short answer would be to use features introduced in Forms Designer 3.0.1:

  • fd.isMobileDevice() and fd.isTabletDevice()JavaScript functions
  • IsMobileDevice and IsTabletDeviceGroup values (available only in On-Premises version of SharePoint).

Before we proceed, however, we need to turn off the SharePoint site feature called ‘Mobile Browser View’ as it’s not compatible with Forms Designer. To do this go to Site Settings → Manage site features (under Site Actions) → click ‘Deactivate’ against ‘Mobile Browser View’.

Let us look at a how we would utilize these features for our use case in both versions of SharePoint.

Designing for mobile devices in SharePoint Online

In Forms Designer for SharePoint Online we have form sets, meaning we can create any number of forms for each of the SharePoint form types (Display, New, Edit). Utilizing our fd.isMobileDevice() and fd.isTabletDevice() we can check if our user agent requires a mobile version of our form and redirect him to it.

Our initial form in Forms Designer:

Design of SharePoint form for PC

Let us add a new form set for ‘New Form’ called ‘Mobile’. To do this, click the ‘+’ button in the top-right corner of the window and get the following dialog:

Form set for mobile devices

We’ll enter ‘Mobile’, click OK.

Here we can design a mobile device-friendly version of our form (don’t forget to click ‘Save’, navigating to another form will cause your changes to be lost):

Design of SharePoint form for mobile devices

What we’ve done here is created a miniature version of our logo, brought out required fields onto the main window to allow for a simpler fill-in process, replaced the tab control with an accordion and made the whole form is fit a regular sized smartphone (by placing everything inside a table and setting the table’s size – which is also a new feature of 3.0.1).

Before we go further, look at the bottom-left corner of the window where it says ‘File: xxxxxx.aspx’. Take a note of this filename, we’ll need it later when we write our JavaScript code.

Now that we have designed our mobile version of the form we need to implement the redirect logic. Let’s go back to our default ‘New Form’ and open up the JS editor. This is the code we will add:


if (fd.isMobileDevice() || fd.isTabletDevice())
{
fd.openForm('fd_Item_e05e9ae8-7eaa-49da-9ad0-0b2fe258e719_NewForm.aspx');
}

What we’re doing here is:

  1. Checking if the user is on a mobile device or tablet with fd.isMobileDevice() || fd.isTabletDevice().
  2. If he is, we’re opening the appropriate form by specifying the filename we have copied above in fd.openForm(filename).

After we’ve pasted in our code with the appropriate filename and saved our form, we’re done. What will now happen is every time a user clicks ‘Add new item’ he will be redirected to a mobile version of the ‘New Form’ if he’s using a mobile phone or a tablet (and if he’s not using a mobile device, he will stay on the initial desktop-friendly form).

The very same procedure would be used if we were creating mobile versions of ‘Edit’ and ‘Display’ forms.

Let’s now have a look at how you could achieve the same thing in SharePoint On-Premises.

Designing for mobile devices in SharePoint On-Premises

The procedure for providing desktop and mobile device versions of a form is even simpler in SharePoint On-Premises: you don’t need to write custom JavaScript code to redirect the user, you can use IsMobileDevice and IsTabletDevicegroup tokens instead.

Let’s open up the ‘New Form’ form in Forms Designer. We will use exactly the same set-up shown in the previous section.

What we’ll do is add a new group by clicking the ‘+’ button in the top-right corner of the window.

Group of SharePoint forms for mobile devices

We’ll call this group ‘Mobile’ and in ‘User-defined rule’ tab we’ll add the following code:


IsMobileDevice || IsTabletDevice

Click ‘Validate’ and ‘OK’.

A new form will be created as a copy of the desktop form. We’ll change it to make it look the way we want, as shown in the previous section.

Click ‘Save’, and we’re done. Now whenever user wants to add a new item he will be directed to the appropriate form, depending on the type of device he’s using.

Passing and getting Date object to and from date and datetime fields

$
0
0

Another new feature we introduced in FormsDesigner 3.0.1 is the ability to interact with date and datetime fields by passing JavaScript Date objects. This feature takes away the need for consumer to think about parsing dates in locale specific formats and simplifies the way date operations are performed on date/datetime fields. Let us take a look at the following use case.

SharePoint issue form

Here we have our old form for creating new issues. Suppose the priority of an issue we set affects the due date for its resolution: high priority implies that the issue is to be resolved within two days, normal priority implies a 5 day period and low priority leaves the due date undefined.

Because the due date periods are pre-defined and are standard for all issues, we want to auto-assign them based on the priority we set. Here’s how we’ll go about doing it: get the current Date object, add the required number of days to it and set the object to our Due Date field.

This is the code we added to our form to achieve this effect:


function setDate(){
var date = new Date();

switch (fd.field('Priority').value()) {
case 'High':
date.setDate(date.getDate() + 2);
break;
case 'Normal':
date.setDate(date.getDate() + 5);
break;
default:
date = null;
}

fd.field('DueDate').value(date);
}

setDate();

fd.field('Priority').change(setDate);

What this code does is:

  1. It defines setDate() method which:
    • Creates a Date object which is initialized with the current date.
    • Checks the value inside the Priority field and depending on it, gets the current date value and adds the respective days offset value.
    • Sets the resulting date object to the field.
  2. It calls the setDate() method when the form is loaded.
  3. And it defines a change event, which calls the setDate() method whenever the Priority value changes.

Now, after we’ve saved our form, we can open it up and see how it works.

Whenever we change the priority value, the due date is automatically readjusted:

SharePoint high-priority issue

High priority.

SharePoint normal-priority issue

Normal priority.

SharePoint low-priority issue

Low priority.

Note

This approach is particularly advantageous if your form is potentially browsed in environments with varying locales, as different locales mean different date formats, which our JavaScript functions take care of.

Inline spreadsheet-style edit mode for the Related Items control on a SharePoint form

$
0
0

Forms Designer has just gotten a new feature: the related items control is now able to do inline spreadsheet-style quick editing. This feature is supported in SharePoint 2013 and SharePoint Online in Office 365. It looks like this:

Edit related items in Quick Edit mode directly from the parent SharePoint form

This mode is available when the render mode of the control is set to ‘Client’. When it is, the ‘Quick Edit’ mode cell in the properties window is enabled, and you can select ‘True’ to enable the mode on the control.

Set Quick Edit property to True

The JavaScript framework has also received a function to auto-fill empty cells in this mode. The name of the function is populateFieldsInGrid, let’s take a look at how it can be used.

In the screenshot we add a new record and only fill in its title:

Adding a SharePoint item in Quick Edit mode from its parent form.

And then we click somewhere outside the row or press Enter, and the record gets saved with some default values that we specified in our JavaScript function:

Auto-populating columns of related items in Quick Edit mode.

The related items control is set to filter items that are only related to the current issue, so what we want to do is set the parent of the new related issue to the current issue, and do it implicitly, behind the scenes.

Filtering related items by the parent field

The way to accomplish this auto-filling functionality is to add a snippet of code to the JavaScript editor and add a CSS class name to the related items control (please note that fields you’re trying to fill in with this function don’t have to be present on the form, like ParentIssue isn’t present on the form but is still filled in by our code).

This is our code:


fd.populateFieldsInGrid($('.related-items'), {
Due_x0020_Date: '12/12/2020',
Assigned_x0020_To: _spPageContextInfo.userId,
Description: 'Related Issue',
Priority: 'Normal (2)',
Additional_x0020_Information: 'This is a supervised issue.',
ParentIssue: GetUrlKeyValue('ID'),
});

And we’ve also added ‘related-items’ CSS Class name to our Related Items control (in the properties window of Forms Designer).

In populateFieldsInGrid function above we specify:

  1. A jQuery selector that contains the Related Items control. You can specify an arbitrary CSS class name in the properties and build the selector based on this class as we did in our sample.
  2. A bunch of fields and their default values. (Note that the field names must be correct InternalNames, found under ‘InternalName’ in the properties window).
    • Due_x0020_Date: a date field. Use the date format that is set on your SharePoint installation (the same format you use when you enter your dates manually).
    • Assigned_x0020_To: a single user field. You can either set the value of such field by id of the user, or by his display name (in this case the format must be '-1;#DisplayName'), or by his email (same format '-1;#EmailAddress'). Note the -1’s here are literally -1’s, not some example ids.
    • Description: a text field. Simply specify the text you wish to enter here.
    • Priority: a single lookup field representing text. Specify textual value of the desired entry.
    • Additional_x0020_Information: a multi check box. Enter exact textual values of yours choices, separated by a semicolon and a space.
    • ParentIssue: a single lookup field to the ID field. Specify the ID value. In our example we use GetUrlKeyValue('ID') function to get the ID of the current element.

Add related items on a new SharePoint form

$
0
0

We are glad to introduce you our new feature that has become available in SharePoint Forms Designer 3.0.5: the ability to create related items inline and link them to the current item automatically, including when you are on the new item form. You may want to read our post about related items auto-fill here before you proceed.

You may have a related items control on your new item form:

Add related items on a new SharePoint form

And you may want to add an item that is related to the current item. In that case you fill out a field, say Title, and click away or press Enter. The entity is created and with default fields filled out automatically.

New SharePoint form with related items.

Then you click Save and a link between the two items is created. Below is the same item opened in display view after saving. As you can see, the related issue is present:

Edit SharePoint form with related items in the quick edit mode

So, how to set this up? First of all, this feature will only work if:

  • You run SharePoint 2013 On-Premises or SharePoint Online.
  • You run Forms Designer version 3.0.5. In order to update Forms Designer in SharePoint Online simply remove the currently installed version and install the new version from the store.
  • The primary list and the related list are located on the same site.

If everything of the above is true, then let’s go through the setup process.

  1. In Forms Designer drop the related items control and set it’s Quick Edit option to “Only”:
    Related Items in quick edit mode on a SharePoint form
  2. Set up the Data Source as you would do normally
  3. Open up the JavaScript editor and paste something like the following:

    fd.populateFieldsInGrid($('.related-items'), {
    Parent: '{CurrentItem}',
    Assigned_x0020_To: _spPageContextInfo.userId,
    Due_x0020_Date: '12/12/2020',
    Description: 'Related Issue',
    Issue_x0020_Status: 'In Progress',
    Additional_x0020_information: 'This is a supervised issue.',
    });

    Draw attention to Parent: '{CurrentItem}'. Parent is a lookup field to the current list, which is being used as the filter by value in the related items control. It can be displayed in the control, but it doesn’t have to. {CurrentItem} is the new token that specifies the current item, using this token allows you to link related items to the current item even when it has not yet been created.

    I won’t discuss the function fd.populateFieldsInGrid and its syntax further here, please see the aforementioned blog post about it if required.

  4. Add ‘related-items’ CSS Class to the related items control. This class is used in fd.populateFieldsInGrid function to identify the related items control.

    That’s it, now the Parent field of inline-created related items will be set to the current item when the item is saved.

Dynamic filtering of the Related Items list on a SharePoint form

$
0
0

Quite frequently our customers ask us how they can dynamically filter their related items lists based on a value entered into a field on a form created in Forms Designer. In this post I will describe how you can do that with a lookup, a drop-down choice and a people picker field. Although I will use these three field types, just about any field type will do for the job.

The steps for implementing this functionality are pretty straight-forward:

  1. Set your related items controls render mode to Client (see screenshot below).
  2. Add a CSS class name to it (see screenshot below). In following samples I will use the “related-issues” class name, if you use something different then replace “related issues” in the code with your class name.
  3. Add the appropriate code to the JS-editor. See code samples below.
Related Items in the client rendering mode

Lookup field

Say we have an issue form with a lookup to a department list and a related items list of other issues. These related issues need to be dynamically filtered based on the value in the Department field. The form will look something like this:

Filtering the related items by a lookup field

When we change the department, the list is refreshed straight away:

Filtering the related items by a lookup field

So, how do we achieve this?

After you have followed through the steps described in the previous section paste the following code into the JavaScript editor of your form:


//first filter on page load
setHash();

//and attach an on-change handler that will call the filtering function wherever the value of the field changes
fd.field('Department').change(setHash);

//this is the actual function that filters the list
function setHash(){
//get value
var value = fd.field('Department').control('getSelectedText');
if (value == "(None)") {
value = "";
}

value = encodeURIComponent(escape(value)).replace(/\-/g, "%252D");

//set the URL’s hash value. An explanation on this is at the end of the article.
window.location.hash = "InplviewHash" + $(".related-issues [webpartid]").attr("webpartid") + '=FilterField=Department-FilterValue=' + value;
}

In this code you will need to replace “Department” with the Internal Name (or Internal Names) of the field you’d like to filter:

  • Where it says fd.field('Department'), Department is the Internal Name of the lookup field that we get our value from.
  • Where it says FilterField=Department Department is the Internal Name of the field in the target list that is being sorted.

In our case the two Internal Names are the same, but they don’t have to be.

And this is it, now our related issues are auto filtered based on the selected Department whenever user changes the value of the Department field.

Dropdown choice field

Here we will do exactly the same thing, but using the Issue Status field, which is a single-value drop-down choice field.

Filtering the related items by a drop-down field

This is the code:


setHash();

fd.field('Issue_x0020_Status').change(setHash);

function setHash(){
var value = encodeURIComponent(escape(fd.field('Issue_x0020_Status').value())).replace(/\-/g, "%252D");
window.location.hash = "InplviewHash" + $(".related-issues [webpartid]").attr("webpartid") + '=FilterField=Issue_x0020_Status-FilterValue=' + value;
}

Here you will need to replace “Issue_x0020_Status” with the appropriate Internal Name(s), for details on this see the Lookup field section above.

Single-value Client-mode people picker field

In this case we want to filter our issues based on the Assigned To field:

Filtering the related items by a user field

This is our code:


setHash();

fd.field('Assigned_x0020_To').change(setHash);

function setHash(){
var value = "";

//if the people picker field really has a value, get it
if (fd.field('Assigned_x0020_To').value() && fd.field('Assigned_x0020_To').value()[0] && fd.field('Assigned_x0020_To').value()[0].DisplayText){
var value = encodeURIComponent(escape(fd.field('Assigned_x0020_To').value()[0].DisplayText)).replace(/\-/g, "%252D");
}

window.location.hash = "InplviewHash" + $(".related-issues [webpartid]").attr("webpartid") + '=FilterField=Assigned_x0020_To-FilterValue=' + value;
}

As with the previous field types you’ll need to swap “Assigned_x0020_To” for the appropriate Internal Name value(s), see the Lookup section for more detail.

Other fields

You can utilize this feature with pretty much any type of field, but you need to know how to retrieve the value of the field. For a list of field types and corresponding ways to retrieve their values check this page: http://formsdesigner.blogspot.com/2013/04/getting-and-setting-sharepoint-form.html.

Explanation

To make this work we are utilizing the SharePoint URL hash feature that is used with SharePoint 2013 views in the client-side rendering mode.

Have a look at this sample URL:
https://mywebsite.com/Lists/Issue/fd_Item_EditForm.aspx?ID=20#InplviewHash3f6a312c-cd80-4e64-be27-075b976ced40=-FilterField1=Parent-FilterValue1=20-FilterField2=Issue_x0020_Status-FilterValue2=In Progress

What our code samples do is set the “InplViewHash” part of the URL together with its FilterField and FilterValue values, which is what tells the related items control to sort the list. Simple as that.


Using ink sketch control in a SharePoint form to place markings on an image from Tablets, iPad, or PC

$
0
0

You can use the sketch control of SharePoint Forms Designer to put markings on an image (note, it won’t add markings to the actual image file but rather it will visually place your markings on top of it).

For example, you may wish to allow your users to draw the directions to somewhere on a map:

Draw on an image in a SharePoint form

Or an insurance company may wish to specify damaged parts of a vehicle on its photographs:

Draw on a picture in a SharePoint form

To set this up you need to be familiar with the ink sketch control, if you are not please read the article.

Once you have you ink sketch control set up, you will need to:

  1. Add a text field to the list, call it PictureURL, place it on the form. This field will contain a URL to the background picture for the ink sketch. Note, you can upload the picture to a document library on you SharePoint site and then just paste the link into this field.
  2. Add the following JavaScript to the form:

    var url = fd.field('PictureURL').value();
    $('.sketch').css('background-image', 'url("' + url + '")');
  3. Add CSS Class ‘sketch’ to the ink sketch control.
  4. Set the ink sketch’s height and width attributes to those of the image and save.

Ink Sketch control of SharePoint Forms Designer

Now the user will need to enter some URL that points to an image file into the PictureURL field, save, reload the form and he will get the ink sketch with the image as the background.

Using a Cross-site Lookup to a SharePoint list with an exceeded threshold limit

$
0
0

In SharePoint there is a default limit of 5000 items that you can add to a list until you are unable to filter that list. For more information on this see here.

What this means in practice is that you are unable to use a SharePoint Cross-site Lookup field that points to a list with an exceeded threshold. In this article we will describe a way of how you can go around the problem.

Note that in SharePoint On-Premises you can increase the threshold limit, for that you can check this article (it’s for SharePoint 2010, but 2013 is the same).

If you cannot or don’t want to change the limit, follow this procedure:

  1. Index the columns that your use to filter the list items by. Here you should include any fields you’re using in the filter=… part of the query (go to Manage Plumsail Lookups → Request items to see code that returns the two queries)
  2. Remove the orderby parameter from the first query (note the lack of the orderby parameter in the following example)

function (term, page) {
if (!term || term.length == 0) {
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField}&$top=10";
}
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField}&$orderby={LookupField}&$filter=startswith({LookupField}, '" + encodeURIComponent(term) + "')&$top=10";
}

Providing different forms for different users in SharePoint Online

$
0
0

If you want to create different forms to different types of users in Forms Designer for SharePoint Online, you have two options: use permission settings or use SharePoint groups. We’ll look at both options in this article.

Suppose we have two types of users on our SharePoint website: managers and regular users. Managers have elevated privileges and we want to give them a particular set of functionality in a form. And regular users should receive a smaller or a different set of functionality and we want to give them a default form.

What we will do first is create an additional form set for managers using the plus button in the top right corner of Forms Designer.

Adding multiple form sets for a SharePoint list

Using permission settings

SharePoint has inbuilt permissions that we will utilize to distinguish managers from non-managers. Please check this list to see the available permissions:
https://msdn.microsoft.com/EN-US/library/ms412690.

We will pick CreateGroups to differentiate managers from non-managers, as only managers are allowed to create groups on our website.

We then will add an html control onto the default form in Forms Designer and paste the following html code inside it:


<Sharepoint:SPSecurityTrimmedControl runat="server" PermissionsString="CreateGroups" EmitDiv="true">
<script type="text/javascript">
fd.openForm('fd_Item_52b1ac46-b55e-4d3c-9807-dec2a57b2e9f_EditForm.aspx');
</script>
</Sharepoint:SPSecurityTrimmedControl>
Using SPSecurityTrimmedControl in a SharePoint form

We have used CreateGroups permission string and the name of the form where we want our managers to be redirected to. The name of the form can be seen if you go to the appropriate form set in Forms Designer (in our case it’s Manager) and pick the appropriate form (in our case it’s Edit Form). That is the form that managers will be redirected onto:

SharePoint form filename

Now whenever a manager opens the default edit form he or she will be redirected to his manager-only form, while a non-manager will stay on the default form.

Using SharePoint groups

Another choice we have to set up user group specific forms is by utilizing SharePoint groups.

For this we’ll need to add a JavaScript script to document library. Create a file named redirect.htm and add the following code to it:


<script type="text/javascript">
ExecuteOrDelayUntilScriptLoaded(function () {
fd.openForm('fd_Item_ee433778-833d-4154-a72f-f68dc876fdc5_EditForm.aspx');
}, 'plumsail.fd.core.js');
</script>

Again, you’ll need to replace the filename as before.

Upload redirect.htm to a document library on your website. Take note of its URL.

Now to go the list with your form sets. Click to edit one of the three forms, we’ll be editing the Edit Form.

Editing SharePoint form page

You’ll be redirected to the default edit form in edit mode, click “Add a Web Part” and add a Content Editor webpart:

Adding Content Editor Web Part to a SharePoint form

Click the Content Editor Webpart’s little arrow button and click Edit.

Enter the URL of redirect.htm into the box:

Setting Content Link property of the Content Editor Web Part

Expand Advanced and enter the SharePoint group members of which you want to be redirected to the additional edit form, in our case it’d be the site collection owners that will be redirected to the Manager edit form:

Settings Target Audiences property of the Content Editor Web Part

Click OK.

Now all members of the group will be redirected to the Manager edit form, while non-members will stay on the default form.

Printing SharePoint forms and exporting to PDF

$
0
0

In this blog post I will describe two new features that Forms Designer has received in the 3.0.7 release. You now have the ability to save your forms to PDF files (without help of a virtual printer) and print them in a printer-friendly way.

You can add the print and export buttons via General Settings in Forms Designer:

Printing options

This will give you two additional buttons in the ribbon:

Print buttons in the ribbon

Printing

Suppose you have a form like this one:

SharePoint form with accordion

As you can see, the form utilizes an accordion control that hides part of the form.

Now, when I click 'Print', the following document is produced:

Printed SharePoint form

As you can see, the document contains just the form without all the extra bits present on the webpage, plus the accordion is expanded, so all of the information is shown in the document.

Note, you can arbitrarily hide UI elements in print mode if you add 'fd-no-print' CSS class to them.

Saving to PDF

You now also have the ability to save PDF versions of your forms via Export to PDF button. Here’s what happens if we use it with our form:

The resulting PDF document contains the form as it is shown on the webpage.

Doing the above programmatically

You don’t have to add the ribbon buttons to use this functionality. You can use the following functions instead:

  • fd.saveAsPDF('invoice.pdf')– this will save the form as a PDF with the name 'invoice.pdf'
  • fd.printForm()– this will print the form

You can use these functions with your own Print/Export buttons or in some other way.

Creating related items on a new item form via a non-grid related items control

$
0
0

In November we released a feature that allows you to create new items and link them to the current item on a new item form. Up until now, however, you could only do that with the related items control in grid mode. Starting from Forms Designer 3.0.8 you are able to do it with a non-grid mode related items control as well.

Let’s illustrate what we’re talking about. Here’s a form:

New SharePoint form with related items

Let’s add a new related contact:

Adding a related item from a new SharePoint form

It appears in the related items control:

New SharePoint form with an attached item

Then we can save the parent item, when we do so a link is created:

Linking related items to a SharePoint item after saving

Implementation

Open the parent New form in Forms Designer.

Set the related items control to 'Show new items only':

Show new related items only

Add the following line of code to the JS-editor:


fd.populateFieldsInGrid($('.related-items'), {
RelatedIssue: '{CurrentItem}'
});

Where RelatedIssue is the internal name of a lookup field on the child list to the parent list and related-items is a CSS class name that you need to assign to the related items control in Forms Designer.

Save.

Open child New form in Forms Designer.

Add an HTML control to the form, set CDATA to false, insert the following code to it:


<div id="_fd_parent_temp">
<asp:HiddenField runat="server" ID="_fd_parent_tempField"
__designer:bind="{ddwrt:DataBind('i','_fd_parent_tempField','Value','Load','ID',ddwrt:EscapeDelims(string(@ID)),'@_fd_parent_temp')}" />
</div>
Setting temporary parent ID in a child new form

Add the following code to the JS editor:


$('#_fd_parent_temp > input').val(window.top.fd._tempParentId());

Save the child form.

Explanation

When we added a related items control and saved the form, Forms Designer added a hidden field called '_fd_parent_temp' to the target list. We then added a hidden '_fd_parent_tempField' control to the child form and bound it to the hidden field. When the child form loads, the JavaScript sets a temporary id of the parent item into _fd_parent_tempField. Finally, when the parent item is saved, Forms Designer checks '_fd_parent_temp' for the parent items’ id and sets the 'RelatedIssue' field to the parent item.

Feel free to ask your questions

Cross-site Lookup to a SharePoint list with more than 5000 items

$
0
0

Today, I wanted to demonstrate how to adjust Plumsail Cross-site Lookup fields for a list with more than 5000 items. As you might know, SharePoint has a constraint on a view that does not allow you to filter or sort a view containing more than 5000 items. This constraint prevents users from searching items in Cross-site Lookup drop-down. Now I will show you how to work around this restriction.

First, you need to create indices for all columns of the source list by which you're going to filter items in the Cross-site Lookup drop-down. By default, the only field that requires an index is the field that you've picked in the 'Field' drop-down of the Plumsail Lookup Manager.

A display field in Cross-site Lookup Manager

Go to the source list's settings and click 'Indexed columns' under the list of columns. Create an index for each column that requires it.

Next, open the Lookup Manager and expand Advanced settings section. In the 'Request items' snippet, you have to remove 'orderby' clause from the first request because SharePoint does not allow you to sort a view containing more than 5000 items even by an indexed column. The result snippet will be:


function (term, page) {
if (!term || term.length == 0) {
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField}&$top=10";
}
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField}&$orderby={LookupField}&$filter=startswith({LookupField}, '" + encodeURIComponent(term) + "')&$top=10";
}

And here you go:

Searching in a list containing more than 5000 items with Plumsail Cross-site Lookup

Please, note that if your filtering criteria is not concrete, say, you typed just a single letter, the result may contain more than 5000 items and you will get an error in the drop-down. Just continue typing to decrease the number of filtered items and you will get the result.

More properties for fields and Kendo Date and Time pickers for dates

$
0
0

In SharePoint Forms Designer 3.1.1 we added a lot of new useful features and here is a short manual of using them.

First, we added changing color, size, and style of font in field`s title and control. Everything is displaying in the field properties.

Customize font style of SharePoint form fields

Second feature is maybe the most significant - now you can define own templates for fields. Just pick ‘Custom’ option in the ‘Template’ property. Next, set custom markup for the control using ‘HTML’ property and custom logic for it with ‘JavaScript’.

Customize view of SharePoint form fields

Another feature we added is pre-defined templates. Currently, they’re available for Date and DateTime fields only. You can change default rendering with Kendo Date and Time picker that looks much better and works faster than the default control.

Replace SharePoint Date and Time fields with Kendo Date and Time pickersKendo Date and Time pickerKendo Date picker

Upgrade the solution and enjoy!


Kendo Editor in SharePoint forms

$
0
0

In SharePoint Forms Designer 3.1.2 we added some interesting features.

First, now Kendo-widgets detect your culture and use right format and language for date and time controls. So, it has become more comfortable to use kendo date and time pickers in forms:

Localizable Kendo date and time picker in SharePoint form

The second feature is a new template for Multiline Plain Text fields - Kendo Editor:

Kendo Editor template for SharePoint multiline text field

In a form, it appears like this:

Kendo Editor in SharePoint form

You can customize toolbar via JavaScript. Here is the complete list of available tools:


"bold",
"italic",
"underline",
"strikethrough",
"justifyLeft",
"justifyCenter",
"justifyRight",
"justifyFull",
"insertUnorderedList",
"insertOrderedList",
"indent",
"outdent",
"createLink",
"unlink",
"insertImage",
"insertFile",
"subscript",
"superscript",
"createTable",
"addRowAbove",
"addRowBelow",
"addColumnLeft",
"addColumnRight",
"deleteRow",
"deleteColumn",
"viewHtml",
"formatting",
"cleanFormatting",
"fontName",
"fontSize",
"foreColor",
"backColor",
"print"

You can get the current list of tools via JavaScript:


fd.field('Text').control('kendoEditor').done(function(editor) {
console.log(editor.options.tools);
});

And set a new list:


fd.field('Text').control('kendoEditor').done(function(editor) {
editor.setOptions({tools: ["bold",
"italic",
"underline",
"strikethrough",
"justifyLeft",
"justifyCenter",
"justifyRight",
"justifyFull",
"insertUnorderedList",
"insertOrderedList",
"indent",
"outdent",
"createLink",
"unlink",
"insertImage",
"insertFile",
"subscript",
"superscript",
"createTable",
"addRowAbove",
"addRowBelow",
"addColumnLeft",
"addColumnRight",
"deleteRow",
"deleteColumn",
"viewHtml",
"formatting",
"cleanFormatting",
"fontName",
"fontSize",
"foreColor",
"backColor",
"print"
]});
});

Here is the editor with full toolbox:

Kendo Editor with all available tools in SharePoint form

Feel free to ask your questions

Viewing all 36 articles
Browse latest View live