PreSaveAction() : Do stuff before form submit

I might be a little late to the party on this one, but I’ve just come across PreSaveAction() for SharePoint forms. This allows you to add a JavaScript function (called PreSaveAction) to a form, and it’ll get called before the form is submitted.

function PreSaveAction() {
	//Manipulate Fields before saving
	//Or perform custom validation
	//There's loads of uses, particularly if also using JQuery.
	return true; //Return false to cancel submit
}

Bizarrely, this has been in SharePoint since SP2007, yet somehow I’ve not come across it before. Clearly, it isn’t as powerful as Display Templates, but that’s a nice feature!

PreSaveAction() : Do stuff before form submit

Strange issue with Application Page and Two Button Presses

Okay, this one was weird. The symptom is this – I had a custom Application page that was being used as the New and Edit forms for a particular custom list in my solution. One of the customisations was that it had an ‘Address Search’ button that, when you pressed, searched for an address based on the first line of the address, or the postcode.

That’s fine, but here’s where things got weird.

  • If you were using the form as a New form, then search worked just fine the first time you clicked it.
  • If you were using the form as an Edit form, the the search button didn’t work the first time you use it – but did the second time you clicked on it.

Bizarre, and I had to fix it… Continue reading “Strange issue with Application Page and Two Button Presses”

Strange issue with Application Page and Two Button Presses

Use jQuery to populate and hide fields in an EditForm.aspx

We’ve got an interesting requirement. We’re using a SharePoint list to store documents which are related to K2 SmartObjects. One of my colleagues is building a custom user control that’s going to show information from this SmartObjects, and associated documents. We want to allow users to

  • click to add a document to our smart object entity
  • upload a file to a library
  • fill in some details
  • automatically associate that file by a GUID

Sounds complicated? Actually, it’s not so hard! Continue reading “Use jQuery to populate and hide fields in an EditForm.aspx”

Use jQuery to populate and hide fields in an EditForm.aspx

Modify ListItem Display to show referencing items…

SharePoint is made up of lists of items, where an item is a set of data. Here is the standard display of an item’s properties:

As you can see, we’ve got a item, and it has some fields of data, and they’re being displayed inside a web part. Those fields are columns on the list:

All very familiar, I’m sure. It gets interesting when we start using Lookup columns, though. These are columns that refer to items in other lists. For example, this is a list of documents, but they refer to items in the above list (that’s what the Item Ref column is doing):

Cool, but wouldn’t it be great if I could show a list of items referring to a particular item on it’s display page? For example, in this case wouldn’t it be good to show a list of ‘Item Documents’ on the DispForm.aspx page used to show the Item’s properties? Well, you can:

(Edit: one of my colleagues points out that Microsoft did this in one of the Fab 40 templates – but I didn’t know).

So how does it work? Continue reading “Modify ListItem Display to show referencing items…”

Modify ListItem Display to show referencing items…

Pages in SharePoint VI – Forms Pages

Forms pages are not really that different to normal pages, but are worth a mention. These are hidden pages inside lists and libraries, and they provide the forms for creating new (and editing existing) items. They exist in a hidden _forms folder in the list:

As you can see, the forms folder for this document library contains quite a number of forms pages! So what do they look like?

Looking in SharePoint Designer at the form page, we see a web part zone containing a web part – in this case the ListFormWebPart. So why is this interesting? Well, we could put our own web part here, should we wish to. For example, you might be recording longitude and latitude on a list item – but that isn’t very intuitive. Instead, we could write a web part to display a map, and use that to update the list item.

In short, they’re not pages I’d expect to edit often – but there is quite a lot you can do with them!

| Intro | Master Pages | Normal Pages | Publishing Pages | Application Pages | Forms Pages |

Pages in SharePoint VI – Forms Pages