Last active
November 1, 2018 18:19
-
-
Save YonatanKra/6e9e1f714a54e26baab90b85701a3f02 to your computer and use it in GitHub Desktop.
Final form file and its usage in the main entry
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import template from './app.html'; | |
import './app.css'; | |
import {YOPFForm} from "../form/form"; | |
export class App { | |
constructor(element) { | |
this._element = element; | |
element.innerHTML = template; | |
this.form = this.setupForm(this._element.querySelector('.phrase-form-wrapper')); | |
} | |
setupForm(element) { | |
const form = new YOPFForm(element); | |
form.listen(this.onPhraseChange); | |
return form; | |
} | |
onPhraseChange(phrase) { | |
alert(phrase); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// get the template | |
import template from './form.html'; | |
// get the styles | |
import './form.css'; | |
export class YOPFForm{ | |
constructor(element) { | |
this._element = element; | |
this.setTemplate(); | |
} | |
setTemplate() { | |
this._element.innerHTML = template; | |
this._form = this._element.getElementsByTagName('form')[0]; | |
this._form.addEventListener("submit", (event)=> { | |
event.preventDefault(); | |
this.onSubmit(event.target); | |
}, false); | |
} | |
onSubmit(form) { | |
this._callback(form.phrase.value); | |
} | |
listen(callback) { | |
this._callback = callback; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment