-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomponent.html
64 lines (57 loc) · 2.36 KB
/
component.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<script>
class TesteComponent {
onInit() {
console.log('Component Initialized', this);
}
isChecked(e) {
return e.isDirty || e.isTouched;
}
isEmpty(e) {
return e.value.trim().length === 0;
}
formIsValid() {
return this.form.isDirty && !this.isEmpty(this.name) && !this.isEmpty(this.age);
}
onClickRegister() {
alert('Name: ' + this.name.value + ', Age: ' + this.age.value);
}
randomColor(e) {
return ['blue', 'red', 'yellow', 'green'][Math.floor(Math.random() * 5)];
}
onlyNumber(e) {
if (!(/^\d*$/.test(e.key))) {
e.preventDefault();
}
}
};
</script>
<component name="teste" controller="TesteComponent">
<form #name="form">
<div>
<label class.has-error="isChecked(name) && isEmpty(name)">Name</label>
<input type="text" #name="name" />
(<label>Clone Sample</label>: <input type="text" #name="nameClone" attr.value="name.value" disabled
style.color="randomColor(nameClone)" />)
</div>
<div if="!isEmpty(name)">
<label>Age</label>
<input type="text" #name="age" event.keypress="onlyNumber($event)" />
</div>
<br />
<div>
<button type="button" prop.disabled="!formIsValid()" event.click="onClickRegister()">Register</button>
<button type="reset" event.click="jRender.component.checkModifications(this)"
title="Verification after click is required! If you want to understand why, remove the event.click attribute from this element.">Default
Reset</button>
<button type="button" event.click="form.reset()">Reset on Event</button>
</div>
<br />
<div>
<div>[Data String]</div>
<div><label>Name</label>: <span prop.innerHtml="JSON.stringify(name.value)"></span></div>
<div><label>Age</label>: <span prop.innerHtml="JSON.stringify(age.value)"></span></div>
<div><label>Form is Dirty</label>: <span prop.innerHtml="JSON.stringify(form.isDirty) || 'false'"></span></div>
<div><label>Form is Valid</label>: <span prop.innerHtml="JSON.stringify(formIsValid())"></span></div>
</div>
</form>
</component>