Showing posts with label jQuery. Show all posts
Showing posts with label jQuery. Show all posts

Tuesday, 19 July 2016

SharePoint accordion with list items, FAQ sample

SharePoint online, Office 365, SharePoint 2013, SharePoint 2010 accordion option / menus, needed depending of how and what data you have to show to the users, here I am writing an example of FAQs section with Accordion as below example is using only jQuery, Css and SPServies to show data from SharePoint list to your page, this sample can be added in App for learning purpose.

<html>
<head>
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
    <TITLE>SharePoint Accordion option using jQuery and css : sample</TITLE>
    <style type='text/css'>
        #AccordionByPraveen {
            list-style: none;
            padding: 0px;
            width: 99%;
            margin: auto;
        }
        #AccordionByPraveen li {
            display: block;
            background-color: #0074C3;
            color: white;
            font-size: 15px;
            cursor: pointer;
            padding: 5px 5px 5px 8px;
            list-style: circle;
            -moz-border-radius: 3px;
            -webkit-border-radius: 3px;
            border-radius: 3px;
        }
        #AccordionByPraveen ul {
            list-style: none;
            padding: 7px;
            display: none;
            border: 1px silver solid;
        }
        #AccordionByPraveen ul li {
            font-weight: normal;
            font-size: 15px;
            font-family: 'segoe ui';
            cursor: auto;
            color: black;
            background-color: #fff;
            padding: 5px 5px 5px 12px;
        }
        #AccordionByPraveen a {
            text-decoration: none;
        }
        #AccordionByPraveen .faqHeadings {
            border-top: 1px white solid;
            padding: 15px;
            font-family: 'Arial Rounded MT Bold';
            font-family: 'Verdana';
        }
        #AccordionByPraveen .faqHeadings:hover {
            background-color: #338DCD!important;
        }
    </style>
    <script type="text/javascript">
        $(document).ready(function(e) {

            $("#AccordionByPraveen > li").live('click', function() {
                $("#AccordionByPraveen > li").css('background-color', '#0074C3');
                $(this).css('background-color', '#00487B');

                if (false == $(this).next().is(':visible')) {
                    $('#AccordionByPraveen > ul').slideUp(400);
                }
                $(this).next().slideToggle(400);
            });
            AddFAQs();
            $('#AccordionByPraveen > ul:eq(0)').show();
            // $('#AccordionByPraveen > ul:eq(0)').parent().css('background-color','#00487B');
        });

        function AddFAQs() {
            var faqListName = "FAQs";
            var camlViewFields = "<ViewFields><FieldRef Name='Title' /><FieldRef Name='Details' /></ViewFields>";
            var htmlLis = "";
            var countLi = 1;
            $().SPServices({
                operation: "GetListItems",
                async: false,
                listName: faqListName,
                CAMLViewFields: camlViewFields,
                completefunc: function(xData, Status) {
                    //alert(Status+faqListName );
                    $(xData.responseXML).SPFilterNode("z:row").each(function() {
                        var ttl = $(this).attr("ows_Title");
                        var ttlDetails = $(this).attr("ows_Details");
                        ttl = countLi + ") " + ttl;
                        htmlLis += '<li class="faqHeadings">' + ttl + '</li><ul>';
                        htmlLis += '<li>' + ttlDetails + '</li></ul>';
                        ++countLi;
                    }); // end completefunc            
                }
            });
            if (htmlLis.indexOf("faqHeadings") > 0) {
                //alert(htmlLis);
                $("#AccordionByPraveen").append(htmlLis);
            } else {
                htmlLis = "<li class='faqHeadings'>FAQ couldn't loaded. Please inform Admin or raise a help ticket with SharePoint team in AskAlexion.</li><ul><li>Details not found.</li></ul>";
                $("#AccordionByPraveen").append(htmlLis);
            }
        }
    </script>
</head>
<body>
    <H2 class="headingFAQPage">Frequently Asked Questions</H2>
    <ul id="AccordionByPraveen">
        <li class="faqHeadings">How can start form to initnin I can nto see sumbit button</li>
        <ul>
            <li>Accordion same data for first li. you can do this and this to open the form</li>
        </ul>
        <li class="faqHeadings">I am new to the site how can I setup my profile </li>
        <ul>
            <li>Contact you website admins or create Help ticket, this is another reply.</li>
        </ul>
        <li class="faqHeadings">Latest feature and upcoming event details can be found at?</li>
        <ul>
            <li>This is the url so site ,http.... and see option number three etc etc.</li>
        </ul>
    </ul>
Original post link is http://makeshortwork.blogspot.in/ 
</body>
</html>


Below is working demo, it may be its not looking perfect as some of the google css are applied here forcefully. 

SharePoint Accordion option using jQuery and css : sample

Frequently Asked Questions

  • How can start form to initnin I can nto see sumbit button
    • Accordion same data for first li. you can do this and this to open the form
  • I am new to the site how can I setup my profile
    • Contact you website admins or create Help ticket, this is another reply.
  • Latest feature and upcoming event details can be found at?
    • This is the url so site ,http.... and see option number three etc etc.

Sunday, 17 April 2016

JQuery Get all SharePoint sites and subsites and show in dropdown dynamically New / Edit form of List

Sometimes SharePoint CSOM/SPO, get all site and sub-sites Url / Name recursively in new or edit forms that needs to add or update a field value by doing little customization, but that little thing leads to research and some coding more then expected as SharePoint OOB features always needs little customization after client demos. well here I am sharing a code snippet that will fetch all sites and subsites Url or Name and add in a dropdown 

<script type="text/javascript" src="/SiteAssets/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="/SiteAssets/jquery.SPServices-2013.01.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){

    var sitePathColumn="Site Path";
    var url="http://myserver";
    var v="";
      $().SPServices({
                operation: "GetWebCollection",
                webURL: url,
                completefunc: function(xData, status) {
                    $(xData.responseXML).find("Web").each(function() {
                        var weburlvar = $(this).attr("Url").replace(url,"");
                        var titlevar = $(this).attr("Title");
                        v+="<option value='"+weburlvar +"'>"+titlevar +"</option>";
                        $().SPServices({
                            operation: "GetWebCollection",
                            webURL: weburlvar ,
                            completefunc: function(xData, status) {
                            var subsite=1;
                                $(xData.responseXML).find("Web").each(function() {
                                    v+="<option value='"+$(this).attr("Url").replace(url,"")+"'>&nbsp;&nbsp;"+subsite+". " + $(this).attr("Title")+" </option>";
                                    subsite++;
                                });
                            }
                        });
                    });
                }
            });   
var DropDown="<TR><TD width='190' class='ms-formlabel' noWrap vAlign='top'><H3 class='ms-standardheader'><NOBR>"+sitePathColumn;
DropDown+=" <SPAN title='This is a required field.' class=ms-formvalidation> *</SPAN></NOBR></H3></TD><TD class='ms-formbody' vAlign='top'><SPAN><select id='configDropDown' onchange='UpdateField();'>"+v+"</select><BR></SPAN></TD></TR>";
        $("td.ms-formlabel h3 nobr").each(function(index){
            if($(this).text().indexOf('*')>0 && $(this).text().indexOf(sitePathColumn)>-1)
                {   
                    $(this).closest('tr').css('display','none');   
                    $(this).closest('tr').parent().prepend(DropDown);   
                }
            if($(this).text()==sitePathColumn)
                {    $(this).closest('tr').css('display','none');    }
        });           
});
function UpdateField(){
$('input[title="Site Path"]').val($("#configDropDown").val());
GetLists($("#configDropDown").val());
}
function  GetLists(siteUrl){

    var clientContext = new SP.ClientContext(siteUrl);
    var oWebsite = clientContext.get_web();
    var collList = oWebsite.get_lists();

    this.listInfoCollection = clientContext.loadQuery(collList, 'Include(Title, Id)');
    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}

function onQuerySucceeded() {

    var listInfo = '';
    for (var i = 0; i < this.listInfoCollection.length; i++) {
        var oList = this.listInfoCollection[i];
        listInfo += '\nTitle: ' + oList.get_title() + ' ID: ' + oList.get_id().toString();
        alert(oList.get_type());
    }
   // alert(listInfo.toString());
}
function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
</script>



if you have any doubt just use comment section or contact form, I'll reply you soon,

Wednesday, 17 February 2016

Caml Query tricks, Properties list, how to use caml, must read for professionals

CAML query to get all items across all folders

<QueryOptions>
        <ViewAttributes Scope="RecursiveAll" />
  </QueryOptions>

Or

query.ViewAttributes = "Scope=\"Recursive\"";


UserID for  current user (here example for Author and Editor)


<Where>
    <Or>
      <Eq>
        <FieldRef Name="Author" />
        <Value Type="Integer">
          <UserID />
        </Value>
      </Eq>
      <Eq>
        <FieldRef Name="Editor" />
        <Value Type="Integer">
          <UserID />
        </Value>
      </Eq>
    </Or>
  </Where>



UTC, Date Time format, 

ISO Caml date time format,

yyyy-MM-ddThh=mm-sss


Today
Offset "-10"
<Where>
      <Eq>
         <FieldRef Name="DueDate" />
         <Value Type="DateTime">
            <Today />
         </Value>
      </Eq>
   </Where>
OR
<Today OffsetDays='-45' />


Date Overlaps

The following example queries for cases where a recurring event overlaps with the current date and time.

<Where>
      <DateRangesOverlap>
         <FieldRef Name="EventDate" />
         <FieldRef Name="EndDate" />
         <FieldRef Name="RecurrenceID" />
         <Value Type="DateTime">
            <Now />
         </Value>
      </DateRangesOverlap>
   </Where>


Lookup ID, Lookup value


<Query>

  <Where>
    <Eq>
      <FieldRef Name="State" LookupId="TRUE" />
      <Value Type="Lookup">68</Value>
    </Eq>
  </Where>
</Query>


Multiple OR condition

<Query>

<Where>
<And>
<Geq><FieldRef Name='TaskDate' /><Value Type='DateTime'>2014-09-24T00:00:00Z</Value></Geq>
<In><FieldRef Name='Author'  />
<Values>
<Value Type='Integer'>650</Value>
<Value Type='Integer'>108</Value>
<Value Type='Integer'>1534</Value>
</Values>
</In>
</And>
</Where> 
</Query>


View Fields Fetch only mandatory columns


<QueryOptions>
        <IncludeMandotoryFields="true" />
  </QueryOptions>



many more to come...