Skip to content

Commit d361ddb

Browse files
Merge pull request swapnilsparsh#100 from anurag97en/master
Issue in Dynamic Form Field swapnilsparsh#78
2 parents 1ffa5ef + df12d9d commit d361ddb

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

07 - Dynamic Form Field/script.js

+9
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,26 @@ var remove_fields = document.getElementById('remove_fields');
44

55
add_more_fields.onclick = function(){
66
var newField = document.createElement('input');
7+
var input_tags = survey_options.getElementsByTagName('input');
78
newField.setAttribute('type', 'text');
89
newField.setAttribute('name', 'survey_options[]');
910
newField.setAttribute('class', 'survey_options');
1011
newField.setAttribute('siz', 50);
1112
newField.setAttribute('placeholder', 'Another Field');
1213
survey_options.appendChild(newField);
14+
if(input_tags.length > 2){
15+
document.getElementById("remove_fields").style.visibility="visible";
16+
17+
}
1318
}
1419

1520
remove_fields.onclick = function(){
1621
var input_tags = survey_options.getElementsByTagName('input');
1722
if(input_tags.length > 2){
1823
survey_options.removeChild(input_tags[(input_tags.length)-1]);
1924
}
25+
else{
26+
document.getElementById("remove_fields").style.visibility="hidden";
27+
28+
}
2029
}

07 - Dynamic Form Field/style.css

+21-1
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,32 @@ input[type="text"]:focus {
5252
}
5353

5454
#add_fields {
55+
background-color: #4CAF50; /* Green */
56+
border: none;
57+
border-radius: 10px;
5558
color: white;
59+
padding: 15px 32px;
60+
text-align: center;
61+
text-decoration: none;
62+
display: inline-block;
63+
font-size: 16px;
64+
5665
}
5766

67+
68+
5869
#remove_fields {
70+
background-color: #ee052c; /* Red */
71+
border: none;
72+
border-radius: 10px;
73+
margin-left: 70px;
5974
color: white;
60-
float: right;
75+
padding: 15px 32px;
76+
text-align: center;
77+
text-decoration: none;
78+
display: inline-block;
79+
font-size: 16px;
80+
6181
}
6282

6383
.controls a {

42 - Simple Form Validation/app.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,23 @@ const isPasswordSecure = function(password) {
2828
const format = new RegExp(/^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*])(?=.{8,})/)
2929
return format.test(String(password))
3030
}
31+
32+
//Only One space between two words will be passed
33+
const isValidUserName = function(username) {
34+
const format = new RegExp(/^([^\s]*[A-Za-z0-9]\s{0,1})[^\s]*$/)
35+
return format.test(String(username).toLowerCase())
36+
}
37+
3138
const validateUsername = function() {
3239
let isInputValid = false
3340
const username = username_input.value.trim()
3441

3542
if (isBlank(username)) {
3643
setError(username_input, "Username can't be blank.")
37-
} else if (!isBetween(username.length)) {
44+
} else if (!isValidUserName(username) ) {
45+
setError(username_input, `Username Invalid`);
46+
}
47+
else if (!isBetween(username.length)) {
3848
setError(username_input, `Username must be between ${min} and ${max} characters.`);
3949
} else {
4050
setSuccess(username_input);

0 commit comments

Comments
 (0)