Welcome to my blog. Here I will try my best to provide as much insight into my Sharepoint creations and whatever other creations I can come up with.
Thursday, January 28, 2010
jQuery Forms Replacement In Sharepoint (Intro)
First off, let me tell you what this series of posts is going to cover. This first post will lay the ground work for my research on using jQuery to replace my Sharepoint forms. The follow ups will go into more details and hopefully a working example.
I want to start with the thought that I am going to try to make my WSS 3 custom sites have a more 2010 like experience as much as I can. So far, it seems that the new version will be all Ajax based and there will be a lot fewer needs to redraw the whole page or do several postbacks to the server just to get stuff done.
With that said, I do have VS 2008 and I can write custom webparts to replace the standard forms. This does work and I like it. However comma (ha ha) every time I want to get/send information to/from the server this required a postback and the whole page needs to be re-drawn. Now, I will honestly tell you that I have not really researched updatepanels so much and I will do that as part of this series.
However, I still wanted to see what I can do with client side scripting and ajax to see if this is feasible for totally replacing a form. So, the first thing I wanted to find out was the quickest way to draw controls that had data from Sharepoint. Let's say I am creating a new item form. These are the questions that I had to answer:
1: Can I write an html file that had all the form controls?
2: Can I write an aspx page that had all the form controls?
3: Do I want to use asp form controls or basic html controls?
4: Do I need to write server side code or can I really do this completely with client side code?
5: How do I tell Sharepoint to use my new form?
There are other things to consider but these were the ones that I thought of up front. So looking at each one:
1: Can I write an html file that had all the form controls?
-- This really is a combination of 1 and 3 and this was hard to decide. I have a lot of coding experience but I have never tried to create some of the controls I knew I was going to need. Plus, Sharepoint and ASP.NET have a lot of nice controls that are not too hard to use.
2: Can I write an aspx page that had all the form controls?
-- As I had stated earlier, I can create this type of page with the code behind needed to get data from SP. This made me wonder if creating an initial aspx page that provides the controls and initial data would be the best choice as I knew how to do that. More on this later.
3: Do I want to use asp form controls or basic html controls? See 1 and 2
4: Do I need to write server side code or can I really do this completely with client side code?
-- Again, this is a combination of the previous points. Having the option of an initial form that is already populated with dropdowns and other things does make it easy to a point. Doing it completely with client side script is possible but is it really feasible to do so? Again, this is a matter of choice. So far, I have not had a lot of success getting that to work. However, thanks to jQuery this might actually be doable. I will get to more of that in just a bit.
5: How do I tell Sharepoint to use my new form?
-- This is going to require custom coding no matter what I do. One idea I had for that was to use a dataview webpart so that I could add modify the links for the New option to go to my new form. This of course would not be feasible unless I did it for every way a user can get to view of that list. I know how to replace the form in the schema file, but that is really not going to work in this case (please let me know if you can get that to work). I am still researching this part.
So, where have I gotten on my quest? Well, what I have tested so far is I have created an aspx page with code behind to draw asp and sharepoint controls on the page just to see if this would work. On a different aspx page I have an iframe inside a hidden div that uses this page as its source. I actually set the source with javascript but I am not sure if I need to or not. I just have a few dropdowns that get data from a few lists. On a click event from a menu I use a jQuery dialog from the jQueryUI library to popup the hidden div with the iframe. This worked! I also added a function to a button on this popup page to see if I can read the contents of a dropdown and this worked as well. The main stumbling point I have now is that I can not seem to use jQuery to attach a change event to the dropdown. Checking the source it has indeed converted the asp dropdown controls to select elements and I have tried different approaches to get a change event attached but it is not working yet. If you have any ideas please let me know! I am confident that I can get the data into sharepoint once I get the forms right. There is a great jQuery library that I plan to use for this. It can be found at http://spservices.codeplex.com The author Marc did a great job with this! I really want to get to the point where I can use it to get data into a list. I know I can also get data out and I am planning on doing that as a second test to compare against the asp form. Again, if you have any suggestions on attaching a change event to the dropdowns let me know. My plan as I just said is to also use the spservices library if this first test does not work. That is where I am at now and I will post again soon as I get more done (or not :) )
Subscribe to:
Post Comments (Atom)
Hey, evilgenius.
ReplyDeleteYou can definitely attach to the change events on the selects. If you look at the SPCascadeDropdowns function in SPServices, you'll see how I'm doing it there.
One thing you could consider as a first step is to just hijack the existing forms with jQuery. SharePoint already lays out all of the right controls for you, so all you need to do is intercept the commit and do your own thing.
Thanks for the kind words about the library!
M.
I thought I saw it somewhere! I will definitely see if I can get that to work.
ReplyDelete