Saturday, July 25, 2015

move sharepoint form fields to your custom form using javascript

<script type="text/javascript" src="//code.jquery.com/jquery-1.10.1.min.js"></script>

<style type="text/css">
 .ms-formbody {
font-family: verdana;
font-size: .7em;
vertical-align: top;
width: 50%;
}
 .ms-formtable
  {display:none;}
</style>

<script type="text/javascript">
    $(document).ready(function() {
        //loop through all the spans in the custom layout        
        $("span.myform").each(function()
        {
            //get the display name from the custom layout
            displayName = $(this).attr("data-displayName");

            displayName  = displayName.replace(/&(?!amp;)/g,'&amp;');
            elem = $(this);
            //find the corresponding field from the default form and move it
            //into the custom layout
            $("table.ms-formtable td").each(function(){
                if (this.innerHTML.indexOf('FieldName="'+displayName+'"') != -1){
                    $(this).contents().appendTo(elem);
                }
            });
        });
    });
</script>

No comments:

Post a Comment