/
index.marko
102 lines (86 loc) · 2.31 KB
/
index.marko
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import { registerSchema, validate } from "class-validator";
class {
onCreate(){
this.state = {
value: null,
validationErrors: []
};
}
onInput(input){
}
onMount(){
registerSchema({
name: this.id, // get id for each component separately from id:scoped in html
properties: {
text: [{
type: "minLength",
constraints: [100],
message: function(args){
console.log(args);
if(!args.value){
return "Text is missing.";
} else {
return "Text is only " + args.value.length + " characters long. Is must be at least " + args.constraints + " characters."
}
}
}]
}
});
}
onFieldInput(event, el){
let value = {text: event.target.value};
this.state.value = event.target.value;
validate(this.id, value).then((errors) => {
this.state.validationErrors = errors;
this.emit('validated', errors);
});
}
}
<div.awly-textarea>
<label>
<div.awly-textarea__label>Insert text at least 100 characters long:</div>
<textarea.awly-textarea__textarea on-input("onFieldInput") placeholder="Insert text here">${state.value}</textarea>
<if(input.validateInline && state.validationErrors.length)>
<div.awly-textarea__message.awly-textarea__message--error>${state.validationErrors[0].constraints.minLength}</div>
</if>
<else>
<div.awly-textarea__message> </div>
</else>
</label>
</div>
style.scss {
.awly-textarea {
display: flex;
width: 100%;
textarea {
outline: none;
}
label {
width: 100%;
}
&__textarea {
padding: 10px;
width: 100%;
box-sizing: border-box;
border: 1px solid #a1a9ba;
border-radius: 2px;
}
&__label {
font-size: 1.2rem;
margin-bottom: 5px;
}
&__message {
padding: 4px 2px;
border-bottom-left-radius: 2px;
border-bottom-right-radius: 2px;
color: grey;
font-size: 0.8rem;
&--error {
color: red;
}
&--success {
color: green;
}
}
}
}