Skip to content

Commit

Permalink
Add URI Fragment support
Browse files Browse the repository at this point in the history
Fix #13

Les champs disponibles sont:
lastname,firstname,birthday,placeofbirth,address,city,zipcode,reason
- "reason" peut etre repete plusieurs fois pour cocher plusieurs motifs.

- "autogenpdf" simule un click pour une generation automatique du pdf.

exemple:
http://.../#lastname=Dupont&firstname=Jean&birthday=01/01/1950&placeofbirth=Paris&address=zzz&city=Paris&zipcode=75000&reason=travail&reason=achats&autogenpdf
  • Loading branch information
christophefontaine committed Nov 28, 2020
1 parent ba233b8 commit 9b3a05c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import './check-updates'
import { prepareForm } from './form-util'
import { warnFacebookBrowserUserIfNecessary } from './facebook-util'
import { addVersion } from './util'
import { autoFill } from './util'
import { createForm } from './form'

warnFacebookBrowserUserIfNecessary()
createForm()
prepareForm()
addVersion(process.env.VERSION)
autoFill()
23 changes: 23 additions & 0 deletions src/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,26 @@ export function addVersion (version) {
'version',
).innerHTML = `${new Date().getFullYear()} - ${version}`
}

export function autoFill() {
const params = new URLSearchParams(
window.location.hash.substr(1) // skip the first char (#)
);
const fields = ["lastname", "firstname", "birthday", "placeofbirth",
"address", "city", "zipcode"]
function fillField(f) {
if (params.has(f) == true) {
document.getElementById("field-"+f).value = params.get(f);
}
}
fields.forEach(fillField);

function checkReason(r) {
document.getElementById("checkbox-"+r).checked = true;
}
params.getAll("reason").forEach(checkReason);

if(params.has("autogenpdf") == true) {
document.getElementById("generate-btn").click();
}
}

0 comments on commit 9b3a05c

Please sign in to comment.