Tweaking out of the box SharePoint 2013 forms - html

I have the following situation. We are building a new intranet for our company and, being a charity, accomplishing AA accessibility is a must. I am a SharePoint developer and we are getting the design from a third party company. That said, designers made a custom design in a way that it is barely recalling SharePoint at all, like a kind of mixture between a completely different design like if it was a publishing site and at the same time, the idea is to work with as much out of the box functionality as possible.
That means that if I create a list, all the look and feel will be the customized one while the functionality must be kept. So I would get a settings page for the list whose functionality should be kept as is but the design should be the new design. A custom list (custom but created in SharePoint) would have a new, editing and display form which should be out of the box... but with the new design.
The problem comes with this out of the box forms. The design is using divs for displaying all the HTML controls that are linked to each of the columns of a custom list. Unfortunately, SharePoint 2013 out of the box list forms tabulate the fields using HTML tables.
Apparently there is a limit of 30000 characters in this post, so I can't paste the code from the out of the box form to show the tables, but what I did is to create a form with an example of each of the possible fields in SharePoint and then look at how many tables I was getting there. And I can't add a screenshot because I need 10 reputation...
I have removed in previous projects the tables in SharePoint webparts using a control adapter, which, by the way, I am using in this website too. But I am struggling with how I can change this HTML tables in the forms. I have tried to render the form same way that I did with the webpart zones but it is not working in a similar way.
Here you have the code for the Control Adapter for webpart zones:
public class WebpartControlAdapter : System.Web.UI.Adapters.ControlAdapter
{
protected override void Render(HtmlTextWriter writer)
{
var wpz = Control as Microsoft.SharePoint.WebPartPages.WebPartZone;
if (wpz != null)
{
WebPartCollection wpColl = new WebPartCollection(wpz.WebParts);
foreach (System.Web.UI.WebControls.WebParts.WebPart wp in wpColl)
{
wp.RenderControl(writer);
}
}
}
}
And here what I tried based on that, which is basically destroying my page completely:
public class PageControlAdapter : System.Web.UI.Adapters.PageAdapter
{
protected override void Render(HtmlTextWriter writer)
{
var currentPage = Control as Page;
if (currentPage != null)
{
System.Web.UI.HtmlControls.HtmlForm form = new System.Web.UI.HtmlControls.HtmlForm();
form = currentPage.Form;
form.RenderControl(writer);
}
}
}
So my question are if anyone has a solution or way to achieve this.
Thanks for any possible help.
P.D.: before you propose that, changing the .aspx files coming OOTB from SharePoint is not an option because we hold other web applications in the same farm and making changes there would provoke changes in all other websites.

I'am not sure what you want to acomplish.
If you are creating totally custom list and want a New, Display and Edit forms completly different then you can define which forms to use in contentType:
https://msdn.microsoft.com/en-us/library/office/aa543825.aspx
Example:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<!-- Parent ContentType: Workflow Task (0x010801) -->
<ContentType ID="0x010100AF4E4BE6CF8048959C4172F4298CE42A"
Name="MyName"
Group="MyGroup"
Description="MyDescription"
Version="0">
<FieldRefs>
</FieldRefs>
<XmlDocuments>
<XmlDocument NamespaceURI ="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">
<FormUrls xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">
<New>_layouts/MyFolder/New.aspx</New>
<Display>_layouts/MyFolder/New.aspx</Display>
<Edit>_layouts/MyFolder/Edit.aspx</Edit>
</FormUrls>
</XmlDocument>
</XmlDocuments>
</ContentType>
</Elements>
In code behind you get current item:
SPListItem item = SPContext.Current.ListItem;
Other possibility is to add script editor webpart on NewFrom, DisplayForm and EditForm. In script use jquery to change look of fields.
To auto populate scriptEditorWebparts you can make eventhandler fired on ListAdded event

Related

How to customize the Jira Issue Collector form that pops up?

Above is what the Issue Collector pop-up form looks like at the moment. This is used to report bugs on a mobile app. When creating the Issue Collector on Jira, I opted for a custom trigger style and a custom template. On Jira, my customization of the template (i.e. the Issue Collector form) is very limited.
I would like to modify the form so that:
More fields (eg Name & Email) are marked 'required', right now only the Summary is marked 'required'.
Multiple fields are displayed on the form. These fields will collect data on, for example OS version, and other specific details.
Is there a way to access the form's HTML code where I can make changes to elements and add more? Otherwise, how can I achieve this through another method?

Reusable HTML Blocks in Sitecore

I'm looking for a way to create a reusable HTML widget for a website run on Sitecore 8. My original idea was to create a data template that basically consisted of a single Rich Textbox. The idea is that you could drop any number of instances of these widgets on a placeholder and it would render out the HTML from each instance of the widget on the page and in the correct placeholder.
Example:
A content item called /products/my-product is based off of "Product" data template
It consists of some fields on the Product template (maybe product name, price)
I'd like the ability for the content editor to quickly drop one or more instances of the HTML widget on the page (say, in the right rail or in a different placeholder on the sublayout. I know I could just throw a "notes" field on the product template, but I'd like to make it more dynamic so that they can add several instances of this HTML widget and place them anywhere they desire.
I quickly realized that because we need the ability for multiple instances of this widget, a data template was not enough because each instance of the widget would needs its own data to populate on the front. Thus, my idea was to allow the content editor to add HTML widgets as a child of the current item (so each item would have its own instance data). I don't think this will work because I don't know of a way to have these children tell the parent page which placeholder to put them in, so laying them out is a problem.
I also thought about somehow setting the placeholder name as a parameter or field on the data template for the HTML widget, but I couldn't figure out how to get Sitecore to dynamically add them to a placeholder when it glues everything together.
Is there a way to achieve what I'm trying to do? Seems like a reusable HTML (or other kind of widget, for that matter) would be a fairly common need. I feel like there's an easy Sitecore way to handle this that I'm missing and overcomplicating the solution.
From what I understand, you're looking for Datasource field of a component.
Basically you:
Create a data template which contains fields necessary for your component
Create a set of items using that templates
Allow authors to select one of them as the Datasource for your component.
It's built in Sitecore functionality.
Check blog post http://firebreaksice.com/using-the-datasource-field-with-sitecore-sublayouts/ or google for Sitecore datasource.
Other links:
http://www.nonlinearcreations.com/Digital/how-we-think/articles/2014/03/4-patterns-Sitecore-component-development.aspx
http://www.nonlinearcreations.com/Digital/how-we-think/articles/2015/04/Sitecore-templates.aspx
EDIT:
Read about Datasource Location field (defining the repository of datasources location) here: http://www.sitecore.net/learn/blogs/technical-blogs/getting-to-know-sitecore/posts/2011/01/handling-presentation-component-settings.aspx
Read about Datasources and MVC here: http://jockstothecore.com/sitecore-mvc-item-maze/

custom/editor tabs order in sitecore

I'm trying to find a way to change order of sitecore custom / editor tabs. by default sitecore displays custom tabs, content tab and dynamic tabs, and according to
https://www.markstiles.net/Blog/2011/02/27/editor-tabs-in-sitecore.aspx
the only way to change order of tabs is to dig into sitecore. sitecore forum isn't helpful either. any ideas if this is configurable in sitecore? above mentioned post is pretty old and sth might have changed since then, but I haven't found any info about it.
As of Sitecore 8.0 update 3, the sitecore code for retrieving the tabs is still the same with the addition of the buckets tab:
Retrieved from Sitecore.Client.dll in the Sitecore.Shell.Applications.ContentManager.Editor class
private static List<Editor.EditorTab> GetEditorTabs(Item item, Editor.Sections sections)
{
Assert.ArgumentNotNull(item, "item");
Assert.ArgumentNotNull(sections, "sections");
List<Editor.EditorTab> editorTabs = new List<Editor.EditorTab>();
Editor.GetCustomEditorTab(item, editorTabs);
Editor.GetCustomEditorTabs(item, editorTabs);
Editor.GetContentTab(item, sections, editorTabs);
if (InternalSettings.ItemBucketsEnabled)
{
Editor.GetNewSearchTab(item, sections, editorTabs);
}
Editor.GetDynamicTabs(item, editorTabs);
return editorTabs;
}
So unfortunately, it looks like this is still the order by which they get rendered. As the article mentions, this could potentially be overridden, but likely to be quite involved.
I've achieved this slightly different. Not 100% satisfied with the solution, but it works until there is a better option.
In my custom tab, that displays as the first tab and therefore the active tab when I select an item. I have added the following JavaScript code to change the active tab back to the standard Sitecore Tab.
parent.scContent.onEditorTabClick(this, null, "Content");
The code goes up to the parent window as the Tab is an iFrame and set the active tab to the "Content" tab.
My custom tab is a SPEAK tab running on Sitecore 8. Here is the SPEAK javascript PageCode for reference.
https://github.com/sobek1985/SitecoreContentEditorTabs/blob/Complete/SitecoreContentEditorTabs/SitecoreContentEditorTabs.js
And a blog post i wrote on the subject too: http://mikerobbins.co.uk/2015/07/14/sitecore-content-editor-tabs-in-speak/

Kendo MVC non-unique id issues

Example: We have an employee list page, that consists of filter criteria form and employee list grid. One of the criteria you can filter by is manager. If the user wants to pick a manager to filter by, he uses the lookup control and popup window is opened, that also has filter criteria and employee list grid.
Now the problem is, that if the popup window is not an iframe, some of the popup elements will have same names and ids as the owner page. Duplicate ids cause Kendo UI to break as by default MVC wrapper generates script tags with $("#id").kendoThingie.
I have used iframe in the past, but content that does not fit in iframe window like long dropdown lists gets cut off and now IE11 especially causes various issues like https://connect.microsoft.com/IE/feedback/details/802251/script70-permission-denied-error-when-trying-to-access-old-document-from-reloaded-iframe.
What would be the best solution here? Generate unique ids for all elements on Razor pages? Modify partial page content that is retrieved by Ajax making ids unique? Something else?
It sounds like you are using a partial page as the content to a Kendo window. If this is the case then just provide your partial with a prefix like so at the top of the page.
#{
ViewData.TemplateInfo.HtmlFieldPrefix = "MyPrefix"
}
Now when you create a kendo control via the MVC wrapper like so
#(Html.Kendo().DropDownListFor(o => o.SomeProperty)
.....
)
The name attribute will be generated as "MyPrefix.SomeProperty" and the id attribute will be generated as "MyPrefix_SomeProperty". When accessing it within Jquery I like a shorter variable name so I usually do
string Prefix = ViewData.TemplateInfo.HtmlFieldPrefix
After setting the prefix. Then use
var val = $('##(Prefix)_SomeProperty').data('kendoDropDownList').value();
Note after this change. If you are posting a form from that partial you will need to add the following attribute to your model parameter on the controller method like so. So that binding happens correctly.
[HttpPost]
public ActionResult MyPartialModal([Bind(Prefix = "MyPrefix")] ModeViewModel model) {
.....
}
Now with all of that said. As long as you keep your prefixes different for each partial your control ids and names will be unique. To ensure this I usually make my prefix name be the same as my cshtml page that I am creating. You would just need to worry about JS function names. Also, note when closing a kendo window all DOM still exist. You just hide it. If this causes you the same issue you just need to be sure to clear the DOM of the modal on close. Similar to how BurnsBA mentioned. Note because of this is the reason why I try to make sure I use the least amount of kendo windows as possible and just reuse them via the refresh function pointing to a different URL.
$('#my-window').data('kendoWindow').refresh({
url: someUrlString
, data: {
someId: '#Model.MyId'
}
}).open().center();
Then on the modal page itself. When posting I do the following assuming nothing complicated needs to happen when posting.
var form = $('#my-form'); //Probably want this to be unique. What I do is provide a GUID on the view model
$('#my-window').data('kendoWindow').refresh({
url: form.attr('action')
, data: form.serialize()
, type: 'POST'
}).open().center();
We do something similar, and have the same problem. We have create/edit/delete popups that fetch data via ajax. Different viewmodels might reference the same model on the same page, and if you open multiple popups (create item type 1, create item type 2) then the second and subsequent popups can be broken (kendo ui error such that a dropdown is now just a plain textbox). Our solution is to delete all dom entries when the popup is closed so there are no conflicts between ids in different popups. We use bootstrap, so it looks like
<script type="text/javascript">
$('body').on(
// hook close even on bootstrap popup
'hidden.bs.modal', '.modal',
function () {
$(this).removeData('bs.modal');
$(this).find('.modal-content').html(''); // clear dom in popup
});
</script>
Note that our popup has some outer html elements and identifiers, but the content is all in
<div class="modal-content"> ... </div>

Using a single shared element across multiple partial views

I have a basic ASP.Net MVC 3 application which has a number of controllers and a number of actions (and subsequently views)
A common feature of the application is to show a pop-up dialog window for basic user input. One of the key features of this dialog process is a faded mask that gets shown behind the dialog box.
Each of these dialog window controls is in a separate Partial View page.
Now, some view pages may use multiple dialog boxes, and therefore include multiple partial views in them - which as is would mean multiple instances of the "mask" element.
What I am trying to find a solution for is to only need to create one instance of a "mask" element regardless of the number of dialog partial views I include, and then the script in each partial dialog will have access to this element (so basically it just needs to be on the page somewhere)
The only real idea I have come up with so far is to add the "mask" element to the master page (or in the original view page) and this will mean it only gets added once. The problem here is that it will be added even when it is not needed (albeit one small single element)
I can live with this, but I would like to know if there is a better way to handle these kinds of scenarios?
A quick idea that came to mind is some kind of master page inheritance hierarchy, So I may have a DialogMasterPage that inherits from the standard current master page. How does that sound for an approach?
Thanks
To do something like this, where each module can register their need for a certain thing in the master page, you can use HttpContext to store a flag of whether you need to write the mask div, and just set that property in each partial. At the end of the master page, if the flag is set, you can then write the mask div if its set to true.
Obviously to make this cleaner you could wrap it all in an HtmlHelper extension or something.
My initial thought is for you to use something like jQuery UI where it handles the masking for you or if you are using something custom you can load the content for the dialog via ajax then show it in the single dialog on the master page.