* Frontend Mentor - Multi-step form solution :PROPERTIES: :CUSTOM_ID: frontend-mentor---multi-step-form-solution :END: This is a solution to the [[https://www.frontendmentor.io/challenges/multistep-form-YVAnSdqQBJ][Multi-step form challenge on Frontend Mentor]]. Frontend Mentor challenges help you improve your coding skills by building realistic projects. ** Overview :PROPERTIES: :CUSTOM_ID: overview :END: *** The challenge :PROPERTIES: :CUSTOM_ID: the-challenge :END: Users should be able to: - Complete each step of the sequence - Go back to a previous step to update their selections - See a summary of their selections on the final step and confirm their order - View the optimal layout for the interface depending on their device's screen size - See hover and focus states for all interactive elements on the page - Receive form validation messages if: - A field has been missed - The email address is not formatted correctly - A step is submitted, but no selection has been made *** Screenshot :PROPERTIES: :CUSTOM_ID: screenshot :END: [[screenshot-desktop.png]] [[screenshot-mobile.png]] *** Links :PROPERTIES: :CUSTOM_ID: links :END: - Solution URL - [[https://efim-frontentmentor-multi-step-form.onrender.com][Live Site URL]] ** My process :PROPERTIES: :CUSTOM_ID: my-process :END: *** Built with :PROPERTIES: :CUSTOM_ID: built-with :END: - Semantic HTML5 markup well, i tried, but yeah - TailwinCSS - Mobile-first workflow - Server-side rendering, in Scala and Cask - htmx - Thymeleaf html templates *** What I learned :PROPERTIES: :CUSTOM_ID: what-i-learned :END: **** hx-get and hx-post ***** How i show correct form stage for each user on same URL on 'index.html' i use "initial loading" element #+begin_src html
loading...
#+end_src This element will do single GET request to server to /get-form And user already has cookie with sessionId set from visiting the root enpoint, which returned 'index.html' So request to /get-form already includes 'sessionId' cookie, and server can find \ initialize Answers data for this particular session, and 'currentStep' is part of the Answers so reloading 'index.html' would trigger /get-form, which would render correct step. ***** hx-post This will make POST request. If we do GET request from only current input value is included, as query para. POST request from or from
would include all filelds of the form. So form submittion on "Next" and "Back" done via htmx POST requests, which parse and save passed attributes, but also server selects required next form step, renders it and returns for the 'hx-swap="outerHTML"' hx-post on allows for 'inline validation' (see useful resources) this allows for validating field value - in isolation or together with all other form field values. **** Learned format in which browser sends POST attributes to the server Request payload as text: name=e&email=emails%40la.la&phone=%2B7%20(911)%2084-35644%20ext%20155 I chose this exercise also because i wanted more experience in working with forms. Single form would still be much nicer, even with htmx, but yeah. Current exercise felt like full-fledged application. **** Styling of the checkbox and radiobuttons as big selectable areas This was first time I attempted something like this. Insight was to use