practicalli / practicalli/clojure-web-services
Question: Web Apps, forms and UI
Nobody has claimed this yet.
- Dominant language
- Markdown
- Stars
- 16
- Forks
- 14
- PR merge metrics
- No merged PRs in 30d
Description
using an MVC architecture in a ring based web app. In a controller function for an edit form, I want to be able to assoc-in multiple bits of data to the request map which include the data for the form itself, data to populate at least one dropdown, and when I get there, validation messaging such as "Name is required".Since the request map isn't mutable, my naive view of a potential solution would be to use a chain of functions to modify the request. Here's what I have now to populate the form with data, depending on if it is a new record or an edit:
(defn edit-nutrient [req]
(view/nutrient-form (nutrient-form-data req)))(defn nutrient-form-data [req]
(if (nil? (get-in req [:path-params :id]))
(assoc-in req [:params :q] [{:eid -1 :name "" :grams-in-stock 0 :purchase-url "" :note ""}])
(assoc-in req [:params :q] (m/find-nutrient (Long/parseLong (get-in req [:path-params :id]))))))
edit-nutrient is the actual controller function and nutrient-form-data a helper function.Now I want to add (assoc-in req [:params :qc] (m/find-all-categories)) to the processing here and feel that this is not a clean approach to passing data into a view, particularly if it requires multiple chunks of data.
Best practice suggestions
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the edit-nutrient and nutrient-form-data functions shown in the issue, then inspect nearby controller and view conventions in the repository. Determine whether the project has an established pattern for supplying form, dropdown, and validation data, and document a clear recommendation if one is needed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- clojure
- Domain
- backend, web-dev
- Issue type
- Documentation
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100