this.on('update', function() { this.root.innerHTML = opts.content }) this.options = [ { value: 'no', text: "» Jag har mindre än två års erfarenhet" }, { value: 'yes', text: "» Jag har mer än två års erfarenhet" } ]; this.options = [ { value: 'kitchen', text: '» Jag vill arbeta i kök' }, { value: 'restaurant', text: '» Jag vill arbeta i matsal' } ]; this.html = opts.placeholder; this.current = -1; this.options = opts.options; next() { this.current += 1; if (this.current >= this.options.length) { this.current = 0; } var option = this.options[this.current]; this.html = option.text; this.value = option.value; this.opts.onchange(this.value); this.update(); } textClass() { if (this.current == -1) { return 'placeholder'; } else { return 'value'; } }
this.html = opts.placeholder; this.current = null; this.rnd = Math.round(1000000 * Math.random()) upload() { this.file.click() } this.on('mount', function() { window.top['upload' + this.rnd] = function(data) { for (k in data) { if (data[k].Filename) { this.html = "Uppladdad fil: " + data[k].Filename + "" this.current = data[k].Hash; this.opts.onchange(this.current); this.update(); } } }.bind(this); this.file.addEventListener('change', function() { if (this.file.files[0].name.toLowerCase().indexOf('.pdf') >= 0) { this.current = null; this.html = "... laddar upp fil..."; this.root.querySelector('form').submit(); } else { alert("Spara dokumentet i PDF-format först."); } this.update(); }.bind(this)); }.bind(this)); textClass() { if (this.current == null) { return 'placeholder'; } else { return 'value'; } }
{errors.firstname}
{errors.lastname}
{errors.email}
+46 70 1234567
{errors.age}
{errors.work}
{errors.experience}
{errors.resume}
{errors.consent}
Skicka changeWork(val) { this.work = val; this.validate(false); } changeExperience(val) { this.experience = val; this.validate(false); } changeResume(val) { this.resume = val; this.validate(false); } changeConsent() { this.validate(false); } submit() { if (this.ready && this.validate(true)) { this.enableLiveValidation(); this.ready = false; function getReferrer() { var cookies = document.cookie.split(";"); for (var ix = 0; ix < cookies.length; ++ix) { var s = cookies[ix]; if (s.indexOf("referrer=") >= 0) { return decodeURIComponent(s.substr(s.indexOf("referrer=") + "referrer=".length)); } } return "n/a"; } var data = { firstname: this.firstname.value, lastname: this.lastname.value, email: this.email.value, mobile: this.mobile.value, age: this.age.value, work: this.work, experience: this.experience, resume: this.resume, referrer: getReferrer(), language: "sv" } this.opts.api.post("/submit/work", data, function(response) { location.href = '/thanks.html'; }); } } this.ready = true; this.errors = {} validate(full) { if (!full && !this._lva) { return; } this.errors = {} if (this.firstname.value.length < 1) { this.errors.firstname = "Måste anges"; } if (this.lastname.value.length < 1) { this.errors.lastname = "Måste anges"; } if (this.email.value.length < 5) { this.errors.email = "Måste anges"; } if (this.age.value.length < 2) { this.errors.age = "Måste anges"; } if (this.mobile.value.length < 7) { this.errors.mobile = "Måste anges"; } if (!this.work) { this.errors.work = "Välj ett alternativ"; } if (!this.experience) { this.errors.experience = "Välj ett alternativ"; } if (!this.resume) { this.errors.resume = "Ladda upp resumé"; } if (!this.consent.checked) { this.errors.consent = "Måste godkännas för att fortsätta..."; } this.enableLiveValidation(); this.update(); for (k in this.errors) { this.ready = false; return false; } this.ready = true; return true; } enableLiveValidation() { if (!this._lva) { this._lva = true; this.root.addEventListener('keyup', this.validate.bind(this)); } }