Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Laravel precognition and update form a11y #359

Merged
merged 3 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions content/collections/pages/contact-form.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
id: 5c526dbf-9dd7-4c52-98d8-54e00ebddfb6
blueprint: page
title: 'Contact form'
updated_by: 9be3d58e-745d-4669-9a70-21c4c5049b89
updated_at: 1627566855
updated_by: ceaa75bd-bc37-4a8b-b0f2-b7af70e58b0e
updated_at: 1698695250
seo_noindex: false
seo_nofollow: false
seo_canonical_type: entry
sitemap_change_frequency: weekly
sitemap_priority: 0.5
page_builder:
-
id: QGsYdcyd
title: 'A contact form'
text: 'This form works with static caching. Both the receiver and the owner of the website will receive a styled e-mail. Forms are dynamic, so just add a field to the forms blueprint and it will work.'
text: 'Both the receiver and the owner of the website will receive a styled e-mail. Forms are dynamic, work with conditional logic and use Laravel Precognition for validation and submission.'
form: contact
type: form
enabled: true
Expand Down
2 changes: 1 addition & 1 deletion lang/en/strings.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

return [
// Contact form
'form_error' => 'There are errors with your form input. Please fix them and try again.',
'form_error' => 'There are problems with your form input:',
'form_honeypot' => 'Fax',
'form_mail_body_owner' => 'A contact form has been sent.',
'form_mail_body_sender' => 'Thanks for your message. We will contact you as soon as possible.',
Expand Down
160 changes: 157 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"@alpinejs/focus": "^3.13.0",
"@alpinejs/morph": "^3.13.0",
"@alpinejs/persist": "^3.13.0",
"alpinejs": "^3.13.0"
"alpinejs": "^3.13.0",
"laravel-precognition-alpine": "^0.5.2"
},
"devDependencies": {
"@csstools/postcss-oklab-function": "^3.0.5",
Expand Down
1 change: 1 addition & 0 deletions public/build/assets/site-c4c8bdf1.css

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions public/build/assets/site-ffb206ad.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions public/build/manifest.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"resources/css/site.css": {
"file": "assets/site-d829b46c.css",
"file": "assets/site-c4c8bdf1.css",
"isEntry": true,
"src": "resources/css/site.css"
},
"resources/js/site.js": {
"file": "assets/site-c558eb30.js",
"file": "assets/site-ffb206ad.js",
"isEntry": true,
"src": "resources/js/site.js"
}
Expand Down
36 changes: 31 additions & 5 deletions resources/blueprints/forms/contact.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,50 @@ tabs:
field:
display: Name
type: text
validate: required
validate:
- required
- 'min:2'
localizable: true
width: 50
width: 66
instructions_position: above
listable: hidden
visibility: visible
replicator_preview: true
input_type: text
antlers: false
hide_display: false
-
handle: email
field:
display: 'Email address'
type: text
validate: required|email
validate:
- required
- email
localizable: true
width: 50
width: 66
instructions_position: above
listable: hidden
visibility: visible
replicator_preview: true
input_type: text
antlers: false
hide_display: false
-
handle: message_body
field:
display: Message
type: textarea
validate: required
validate:
- required
- 'min:5'
localizable: true
instructions_position: above
listable: hidden
visibility: visible
replicator_preview: true
antlers: false
hide_display: false
-
handle: consent
field:
Expand Down
17 changes: 3 additions & 14 deletions resources/js/site.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
import Alpine from 'alpinejs'
import collapse from '@alpinejs/collapse'
import focus from '@alpinejs/focus'
import morph from '@alpinejs/morph'
import persist from '@alpinejs/persist'
import focus from '@alpinejs/focus'

// Global get CSRF token function (used by forms).
window.getToken = async () => {
return await fetch('/!/statamic-peak-tools/dynamic-token/refresh')
.then((res) => res.json())
.then((data) => {
return data.csrf_token
})
.catch((error) => {
this.error = 'Something went wrong. Please try again later.'
})
}
import precognition from 'laravel-precognition-alpine';

// Call Alpine.
window.Alpine = Alpine
Alpine.plugin([collapse, focus, morph, persist])
Alpine.plugin([collapse, focus, morph, persist, precognition])
Alpine.start()
Loading