Showing posts with label JQuery. Show all posts
Showing posts with label JQuery. Show all posts

Thursday, 12 February 2015

SharePoint 2013: How to get current user name using spservices.js

How to get current user name using spservices.js:

Then download the SPUtility.js file from http://spservices.codeplex.com/ and jquery-1.11.2.min.js file as well.

<script type="text/javascript" src="/Style Library/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="/Style Library/spservices.js"></script>

$(document).ready(function() {      
        var currentAbsoluteUrl = window.location.protocol + "//" + window.location.host;
        var currentUserName= $().SPServices.SPGetCurrentUser({
        webURL:currentAbsoluteUrl,
        fieldName: "Title",
        debug: false
    });
  alert('User Name:'+currentUserName);
});

How to use SPUtility.js file in SharePoint list form for Hide/Show the columns, set a DropDown Changed event and RadioButton changed event using Jquery

How to use SPUtility.js file in SharePoint list form for Hide/Show the columns, set a DropDown Changed event and RadioButton changed event using Jquery:

For this, you should add a content editor webpart inside newform.aspx, where you want to show/hide the list columns. 
Then download the SPUtility.js file from http://sputility.codeplex.com/ and jquery-1.11.2.min.js file as well. we have to add a below script inside content editor WebPart. then it will works.

<script type="text/javascript" src="/Style Library/sputility/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="/Style Library/sputility/sputility.min.js"></script>

<script type="text/javascript">


function OnStatusFieldDropdownChange(spfield) {
    var statusFieldValue = spfield.GetValue(); 
           
    if(statusFieldValue === '4-Closed') {
        SPUtility.GetSPField('Resolved By').Show();
       
        
    } else{ 
        SPUtility.GetSPField('Resolved By').Hide();
        
    }   
}

function OnRadioButtonsChange() {
    var statusFieldValue = SPUtility.GetSPField('Reference Type').GetValue();
    if(statusFieldValue === 'File Attachment') {
        SPUtility.GetSPField('Revision Date').Show();
        SPUtility.GetSPField('URL').Hide();
    } else{
        SPUtility.GetSPField('Revision Date').Hide();
        SPUtility.GetSPField('URL').Show();
    }
}

$(document).ready(function() {


SPUtility.GetSPField('Title').Show();
SPUtility.GetSPField('Resolved By').Hide();
SPUtility.GetSPField("Title").SetValue('Sample Value').MakeReadOnly();

//Set DropDown chnaged event
var statusFieldValue = SPUtility.GetSPField('Status');
 $(statusFieldValue.Dropdown).on('change', function() { 
        OnStatusFieldDropdownChange(statusFieldValue);
    });

//Set Radiobutton changed event
var RreferenceTypeRadio = SPUtility.GetSPField('Reference Type');
$(RreferenceTypeRadio.RadioButtons).each(function(index, obj) {
        var radioButton = obj.value;
        $(radioButton).change(OnRadioButtonsChange);
    });
      
});
</script>

SharePoint 2013: Show Modal Popup Window in Application Page

Show Modal Popup Window in Application Page

I want to show the modal Popup window from my application page, for that we need to call the below JS file inside your application page.

<script type="text/javascript" src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.js"></script>

And the call the Jquery function for modal Popup your application page as below we called:

<script type="text/javascript">
        function showModalPopup() {
            alert('Bala testing on this');
            try {
                var options = {
                    width: 630,
                    height: 500,
                    title: "Edit SR Request",
                    bgcolor: '#000000',
                    url: "/_layouts/15/GridVewSort/Seekopinion.aspx?Reqno=USA&list=countries",
                }
            }
            catch (e) {
            }
            SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);
            return false;
        }
</script>

If you want to cancel the modal Popup window without refresh your screen. you can use below script in cancel button client click:

<asp:Button ID="btnCancel" runat="server" Text="Cancel"  CssClass="btnclass" OnClientClick="javascript: window.frameElement.commitPopup();" />