Simple Styling of EPiServer Forms

Prior to EPiServer Forms 4.5, we were forced to inject in our own styling by editing the less files. This often resulted in breaking functionality where javascript were dependant upon these base CSS classes. EPiServer last year changed this by binding javascript to data attributes freeing us from styling shackles.

This article is for those that are struggling to put the pieces of styling EPiServer Forms together and want a straight forward example.

  1. Implement a class inheriting from IViewModeExternalResources
  2. Create your custom style sheet
  3. Add in Styles to match EPiServer Forms Markup
  4. Build, Run & Test

 

1. Implement a class inheriting from IViewModeExternalResources

Create the follow class anywhere in your solution:

[ServiceConfiguration(ServiceType = typeof(IViewModeExternalResources))]
public class EPiServerFormsViewModeExternalResources : IViewModeExternalResources
{
   public IEnumerable Resources
   {
      get
      {
         var rcList = new List();
         rcList.Add(new Tuple("css", "/YourCssPath/CustomEPiServerForms.css"));
         return rcList;
      }
   }
}

 

2. Create your custom style sheet

Create a css class anywhere in your solution and update the path in step where the text is bold in the previous step.

 

3. Add in Styles to match EPiServer Forms Markup

So here is where your front end designer comes in. You’ll need to provide the markup that will allow them to identify which classes style check section of the form.

Here’s an example for the textbox element

/* Textbox Element */
   .FormTextbox .Form__Element__Caption {
   color: orange;
}
   .FormTextbox .FormTextbox__Input {
   color: red;
}

The TextBox element will appear as follows on the episerver form:

EPiServerFormsColouring

Examples of other elements with their css classes:

Form Element HTML Tag class name
Textbox label .FormTextbox .Form__Element__Captio
Textbox input .FormTextbox .FormTextbox__Input
Number label .FormTextbox–Number .Form__Element__Captio
Number input .FormTextbox–Number.Form .Textbox__Input
Submit button .Form__Element .FormSubmitButton

You can investigate the remaining elements by looking at the ascx files located in EPiServerForms module folder in the ElementBlocks section:

WithEPiServerFormsStyling

 

4. Build, Run & Test

Run the solution and navigate to the page where you’ve setup your EPiServer Forms example.

You will find that your css should be getting loaded in along with the page.

If a style isn’t getting applied but you know it’s being attached to the html tag then try applying the css keyword !important. Sometimes you may be using bootstrap classes and that is overriding your styles.

EPiServer Forms – Quick Start

I was asked once by a client to build some functionality that allowed editors to create forms on the fly without developer effort. EPiServer did the work for us. Here’s an overview on Forms.

Out of the box EPiServer Forms boast the following form elements ready to use:

  • Text, Text Area, Number, DateTime, Range, Url, Rich text
  • Selection, single/multiple choice
  • Image, File uploads
  • Hidden Values, Hidden Visitor Profiling
  • Captcha, Recaptcha
  • Form, Submit, Reset buttons.

All in all, covers most scenarios.

To get started:

  1. Install EPiServer.Forms package via NuGet in Visual Studio
  2. A new tab called Forms will appear in your assets pane alongside Media and Blocks tabs
  3. Click the create new form button in the Forms tab
  4. Once you’ve populated some details about your form, Create it and then you will see a new Forms Elements section in the Forms Tab. From here you can drag over what you need into the form.
  5. At the very minimum you should drag the Submit button over to allow a user to submit the form.
  6. The form itself in the settings tab allows you to add a list of email recipients for where the form data will be sent to.
  7. The form is block based and thus must be dragged into a Content Area for it to be used.

This is your basic form done. Within that you can configure all the out of the box form elements. There are lots of options such as setting Required flags, range limits, regular expressions and even formats.

EPiServer documentation as a create selection of how-tos for different types of forms: http://webhelp.episerver.com/latest/addons/episerver-forms/form-examples.htm

Exception: Cannot find compilation library location for package ‘Microsoft.AspNetCore’

System.InvalidOperationException: Cannot find compilation library location for package ‘Microsoft.AspNetCore’

Most likely you’ve upgraded your aspnetcore version and you have not cleared the existing files before deployment.

If you’re using Azure DevOps as your build and release server you can enable “Remove Additional Files at destination” on your release step.

AspNetCore Debugging Startup issue in Azure Web App

Whilst upgrading from AspNetCore 2.0 to 2.1, some of the StartUp configuration had changed slightly and part of the upgrade required me to refactor code into the webhost builder. However as a result I didn’t quite do everything and after deploying to azure web app, I was hit with a 502 response. An exception being thrown in main(). This was a problem because it was happening before it could get to my logging initialization and therefore no logging was happening.

So in order to debug Azure Web App AspNetCore startup issues we need to enable stdout logging which throws all exceptions to a log file. This method of logging is unfiltered and gets heavy very quickly. Therefore it is inadvisable to keep it turned on.

Enable STDOUT on Azure Web App

  1. Go to your azure web app in Azure Portal
  2. Open Kudu Console
  3. Using the navigation bar at the top of the page, open Debug console and select CMD
  4. Navigate to folder site > wwwroot
  5. Edit the web.config
  6. Set stdoutLogEnabled to true and stdoutLogFile to \\?\%home%\LogFiles\stdout
  7. Select Save
  8. Make a request to the application url
  9. In Kudu, navigate to the LogFiles folder
  10. Open the new files marked with stdout
  11. When the log file opens, the error is displayed.
  12. you must disable stdoutLogEnabled by setting to false when you are done

 

Source: https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/azure-apps/troubleshoot?view=aspnetcore-2.1#aspnet-core-module-stdout-log

AspNetCore 2.1.3 + Azure Web App + 502.5 Error

Anyone updating to AspNetCore 2.1.3 to an Azure Web App may want to hold off. Azure Deployments hasn’t been updated yet and is scheduled to be completed in a weeks time.

Downgrade to Microsoft.AspNetCore.App 2.1.0 for now.

Source: https://blogs.msdn.microsoft.com/dotnet/2018/08/21/net-core-august-2018-update/

EPiServer Find Index – unknown property

This particular nugget has screwed with me for a few days. When attempting to run a standard EPiServer Find index, my log files were getting flooded with this:

An exception occurred while indexing (Content): MapperParsingException[failed to parse [Blocks.Items.Blocks.Items.DefaultPrice.UnitPrice.Currency]]; nested: ElasticSearchIllegalArgumentException[unknown property [CurrencyCode$$string]]; .

Contact episerver support to get them to move your index to a new cluster. In my case it was confirmed by EPiServer support that it was a timeout issue with regards to a bad cluster the index is sitting on.

Similar: https://support.episerver.com/hc/en-us/articles/115004105763-Find-Index-Timeout-with-OnPublish-Event

The Importance Of Sprint Planning

Sprint planning is the first ceremony in the SCRUM cycle. I’ve seen varying implementations of sprint planning depending on the client I’m working and often it works very well. Occasionally however, I have worked with clients where the entire team including the management decide to prioritize it under everything else.  For me this just screams tragedy, so here comes my perspective on the importance of sprint planning.

Wait…I thought I was the striker?

A team without sprint planning is kind of like a football team without a tactics drill session and game strategy.  You could knock a team together, buy the kit and then when it comes to the first game everyone is running amok the entire time.  I’ve seen this happen in scrum teams.

Dedicated time assigned to planning allows the team to focus on the business requirements. This is the time where gaps in requirements are raised, misunderstandings are brought to the surface and most importantly solutions are created as a team.

Let me just get on with it

Often without planning, developers will start coding immediately in isolation without taking into consideration the other in-progress user stories.  Potentially these clashes don’t appear until much later in the sprint and then there is a rush to refactor code conflicts and address requirement conflicts – This increases exponentially when there are more dependencies between stories.

Isolated developers will also create solutions using patterns best suited to their experience.  If not agreed upon within the planning session, you will find similar & related business requirements implemented in several different ways. These can result in increased code duplication, complexity in refactoring and adding to technical debt.

Suck it up princess

From a moral perspective, sprint planning is an excellent time to get the team on the same page.  The team decide which user stories are committed to the sprint – not the lead developer, not the product owner…the team.  The sprint is delivered as a team,  so commitments must be made as a team.  By allowing the team to decide what can be delivered will give a sense of responsibility and ownership.  I have often found teams that feel this, will achieve more and higher quality.

Some managements will try and push more into the sprint at the beginning and this only creates negative feeling and lack of control.  The team must feel the committed stories are achievable else efficiency will suffer before the sprint has even started. Remember more back log items can always be added to the sprint if the team is achieving and capacity across all roles is there.

Incomplete work from the previous sprint can also tempt developers to skip the session in the following sprint.  Not only will they have to play catch up in term of understanding the requirements, they will also lose their participation in estimates and any valuable experience they have gained as an individual will not be available to the rest of the team whilst solutions are being discussed.

Why don’t we try

Sprint planning is a part of agile and that in-itself should be subject to constructive criticism. If you find your current way of planning isn’t working then discuss the problems and draw actions from them. Does the product owner or scrum master need to attend the entirety of the session? Can the session be split up into parts? Maybe the PO and BA can spend the first hour discussing the user stories so that the scrum team can be left to work out the solutions and task breakdown.

Visual Studio 2017 – Add, Remove or Update DotNetCLITools references – 7th March 2017

Visual Studio release notes as of 7th March release notes state that the DotNetCLITools packages cannot currently be managed by the Nuget Package Manager and must be edited manually in the csproj.

After migrating my current projects, I finally figured out that it wasn’t just me that was struggling to find the place to manage these packages. There’s no intellisense in this area either. Eventually I replaced my pre-release references with the following:

In your csproj file: 

<ItemGroup>
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" />
    <DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="1.0.0" />
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0" />
    <DotNetCliToolReference Include="BundlerMinifier.Core" Version="2.2.301" />
 </ItemGroup>

This allows visual studio to run the dotnet commands for building, database, bundling and publishing!

Sources: https://www.visualstudio.com/en-us/news/releasenotes/vs2017-preview-relnotes

My Resharper license just expired…renew or not to renew

It’s that time of the year again when the licenses on my third party products start lapsing and I pull out my card to renew for another year. Although having used Resharper for a long time, the line between it and Visual Studio has blurred for me. So instead I’ve decided not to renew and use VS2015 vanilla style.

Off the bat, VS 2015 suddenly became blistering fast. The start up, loading a solution and even the vanilla refactoring tools became almost instant. I don’t seem to remember having this problem when I was using VS 2013 but I have definitely felt it in VS 2015. I am rocking a SSD & i7, I can’t help but feel Resharper was slowing me down which is the opposite reason as to what I bought it for in the first place. Out of the thousands tools it does offer, I felt I was only using maybe 10 of them?

I’ve been off Resharper for a few days and I am actually enjoying the change. Two features I do miss so far is Continuous code analysis using StyleCop and Continuous Testing using dotCover. VS 2017 enterprise edition introduces Live Unit Testing which should hopefully fill this void.

I’m going to give vanilla VS2015 another week or so then I’ll try some of the open source options. I did come across this little gem as a free alternative to the paid providers: http://vsrefactoringessentials.com/