Pages

Showing posts with label Jquery. Show all posts
Showing posts with label Jquery. Show all posts

Thursday, March 21, 2013

Jquery Redirect After save an item from NewForm.aspx and EditForm.aspx

Hello all

I came across to an situation where user needs to redirect to a "Thank You" or lets say different page when they save item fron "NewForm.aspx" or "EditForm.aspx".

As I do not want to use Visual Studio code that ater save item Event Receiver - "ItemAdded" I tried to look around is there any other option available like Jquery , and yes we can , so easy :)

Here is the code for that.

$(document).ready(function() {

        var button = $("input[id$=SaveItem]"); 
// change redirection behavior 
button.removeAttr("onclick"); 
 button.click(function() { 
             var elementName = $(this).attr("name"); 
             var aspForm = $("form[name=aspnetForm]"); 
             var oldPostbackUrl = aspForm.get(0).action; 
             var currentSourceValue = GetUrlKeyValue("Source", true, oldPostbackUrl); 
             var newPostbackUrl = oldPostbackUrl.replace(currentSourceValue, "custompageurl.aspx"); 
   
             if (!PreSaveItem()) return false; 
             WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(elementName, "", true, "", newPostbackUrl, false, true)); 
         }); 
});

Enjoy Jquery!
Disha Shah

Thursday, March 1, 2012

How to get username from JQuery

Hello Friends


Use below Jquery to get the Current User name
var thisUserAccount = $().SPServices.SPGetCurrentUser({
                fieldName: "Title",
                debug: false
});

Use below code to get the ID for Current User
var thisUserAccount = $().SPServices.SPGetCurrentUser({
                fieldName: "ID",
                debug: false
});

Use below code to get the LoginName for Current User
var thisUserAccount = $().SPServices.SPGetCurrentUser({
                fieldName: "Name",
                debug: false
});

Disha Shah

Wednesday, August 24, 2011

SharePoint 2010 :JQuery Magic SPCascadeDropdowns with the same list

Hello Friends


I have this below situation in which all SharePoint lists has been created  and deployed to the production and Users are using this list , their list structure is like this.


First List ,name is "Country" list  which contains "title" field is text field and act as "Country" and "State" field contains name of the State in that country.


Below  is the "City" list in which  we have Country and State as Lookup column and "Lookup" list is "Country" and City name will come under the "Title" field.


Now, on production actual problem has been started when they insert the city inside the list,  because country and state has not been cascading. It is production and people already using it. How to add atleast the minimum cascading so user select the right state depends on country.

Let us use the magic of JQuery.

Here is simple javascript code that I have used to accomplish this.

<script language="javascript" src="/Shared%20Documents/jquery-1.3.2.min.js" type="text/javascript"></script><script language="javascript" src="/Shared%20Documents/jquery.SPServices-0.6.2.min.js" type="text/javascript"></script><script language="javascript" type="text/javascript">

var sCamlQuery = "";
$(document).ready(function() {

// Cascade definition for State dropdown
$().SPServices.SPCascadeDropdowns({
    relationshipList: "Country",
    relationshipListParentColumn: "Title",
    relationshipListChildColumn: "State",
    parentColumn: "Country",
    childColumn: "State" ,
    completefunc: function() {
        sCamlQuery = "<Eq><FieldRef Name='Title'/><Value Type='Text'>" + $("select[title='Country'] option:selected").text() + "</Value></Eq>";
    }
  });
});</script>

After add this script inside the "Content Ediotr Webpart" we have below results, users happy , we happy.























Exact thing what we need!!!
Thanks JQuery!!!

Disha Shah

Wednesday, March 16, 2011

JQuery with a small example

Hello friends
I was just trying to use JQuery with SharePoint sites and here is the very basic example which toggles button.

Notes:  In JQuery, we can refer object with its ID by using #. ".toggle()" this function is already available inside the JQuery , so we just have to name it which saves time

Example:
$('#exapandButton').click(function()
{
$('#warning').toggle();
if ($('#warning').is(':visible'))
{
$(this).val('Hide');
}
else
{
$(this).val('Show');
}
}
);