-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hw#4 #6
Open
PeregudovN
wants to merge
3
commits into
GeekBrainsTutorial:master
Choose a base branch
from
PeregudovN:HW#4
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Hw#4 #6
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
*{ | ||
margin: 0 auto; | ||
padding: auto; | ||
|
||
} | ||
body{ | ||
background-color: #dedaeedd; | ||
} | ||
header{ | ||
display: grid; | ||
grid-template-rows: 1fr; | ||
justify-content: flex-end; | ||
background-color: #cccc; | ||
} | ||
.btn-cart{ | ||
padding: 10px 50px; | ||
background-color: #fff; | ||
} | ||
main{ | ||
display: grid; | ||
grid-template-columns: 1fr; | ||
} | ||
.products{ | ||
display: grid; | ||
grid-template-columns: 1fr 1fr; | ||
grid-template-rows: 1fr; | ||
} | ||
.product-item{ | ||
border: 1px solid black; | ||
display: block; | ||
width: 350px; | ||
height: 200px; | ||
margin: 5px; | ||
} | ||
.product-item h3{ | ||
color: red; | ||
font-size: 30px; | ||
margin: 5px; | ||
} | ||
.product-item p{ | ||
font-weight: 600; | ||
font-size: 18px; | ||
margin-left: 10px; | ||
} | ||
button{ | ||
margin: 5px; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<link rel="stylesheet" href="css/style.css"> | ||
<title>Title</title> | ||
</head> | ||
<body> | ||
<header> | ||
<button class="btn-cart">Cart</button> | ||
</header> | ||
<main> | ||
<div class="products"></div> | ||
</main> | ||
<script src="js/main.js"></script> | ||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const data = [ | ||
{ title: 'Notebook', id: 1, price: 2000 }, | ||
{ title: 'Keyboard', id: 2, price: 200 }, | ||
{ title: 'Mouse', id: 3, price: 100 }, | ||
{ title: 'Gamepad', id: 4, price: 87 }, | ||
{ title: 'Новый Товар', id: 5 } | ||
]; | ||
const renderProduct = (title, id, price = 'Цена товара', img = "https://placehold.it//150x100") => { | ||
return ` | ||
<div class="product-item"> | ||
<img src = "${img}" alt = "${title}"> | ||
<div> | ||
<h3>${title}</h3> | ||
<p>${price}</p> | ||
<button>Купить</button> | ||
</div> | ||
</div> | ||
` | ||
}; | ||
|
||
const render = (products) => { | ||
document.querySelector('.products').innerHTML = products.map(item => renderProduct(item.title, item.id, item.price)).join(''); | ||
}; | ||
|
||
render(data); | ||
console.log(data) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
const validateParams = { | ||
name:{ | ||
pattern:/^[a-zа-яё]+$/i, | ||
error:'Имя должно содержать только буквы' | ||
}, | ||
phone:{ | ||
pattern:/^\+7\(\d{3}\)\d{3}-\d{4}$/, | ||
error:'Телефон должын быть в форме "+7(000)000-0000"' | ||
}, | ||
email:{ | ||
pattern:/^[\w\.-]+@\w+\.[a-z]{2,4}$/i, | ||
error:'Email должен выглядеть как [email protected]' | ||
} | ||
}; | ||
|
||
class Validator{ | ||
static errorClass = 'error-msg'; | ||
form =null; | ||
params = null; | ||
valid = false; | ||
|
||
constructor(form,params){ | ||
this.form =document.querySelector(form); | ||
this.params = params; | ||
this._init(); | ||
} | ||
_init(){ | ||
this.form.addEventListener('submit', e =>{ | ||
this._validateForm(); | ||
if(!this.valid){ | ||
e.preventDefault(); | ||
} | ||
}) | ||
} | ||
_validateForm(){ | ||
this.valid = false; | ||
const errors = [...this.form.querySelectorAll(`.${Validator.errorClass}`)]; | ||
for(let error of errors){ | ||
error.remove(); | ||
} | ||
const formFields = [...this.form.querySelectorAll('input')]; | ||
|
||
for(let field of formFields){ | ||
this._validate(field); | ||
} | ||
|
||
if(![this.form.querySelectorAll(`.invalid`)].length){ | ||
this.valid = true; | ||
} | ||
|
||
} | ||
_validate(field){ | ||
if(!this.params[field.name]){ | ||
return; | ||
} | ||
const {pattern,error} = this.params[field.name]; | ||
|
||
if(!pattern.test(field.value)){ | ||
field.classList.add('invalid'); | ||
this._addErrorMsg(field,error); | ||
this.watchField(field,pattern,error); | ||
} | ||
} | ||
_addErrorMsg(field,error){ | ||
const errorBlock = `<div class ="${Validator.errorClass}">${error}</div>`; | ||
field.parentNode.insertAdjacentHTML('beforeend',errorBlock); | ||
} | ||
watchField(field,pattern,error){ | ||
field.addEventListener('input',() =>{ | ||
const errorBlock = field.parentNode.querySelector(`${Validator.errorClass}`); | ||
if(pattern.test(field.value)){ | ||
field.classList.remove('invalid'); | ||
field.classList.add('valid'); | ||
if(errorBlock){ | ||
errorBlock.remove(); | ||
} | ||
}else{ | ||
field.classList.remove('valid'); | ||
field.classList.add('invalid'); | ||
if(!errorBlock){ | ||
this._addErrorMsg(field,error); | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
|
||
window.onload = () =>{ | ||
new Validator(`#myform`,validateParams) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link rel="stylesheet" href="style.css"> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
<div class="text"> | ||
<p> | ||
One:В 'Hi Mary.' Two:В 'Oh, hi.' | ||
One:В 'How are you doing?' | ||
Two:В 'I'm doing alright. How about you?' | ||
One:В 'Not too bad. The weather is great isn't it?' | ||
Two:В 'Yes. It's absolutely beautiful today.' | ||
One:В 'I wish it was like this more frequently.' | ||
Two:В 'Me too.' | ||
One:В 'So where are you going now?' | ||
Two:В 'I'm going to meet a friend of mine at the department store.' | ||
One:В 'Going to do a little shopping?' | ||
Two:В 'Yeah, I have to buy some presents for my parents.' | ||
One:В 'What's the occasion?' | ||
Two:В 'It's their anniversary.' | ||
One:В 'That's great. Well, you better get going. You don't want to be late.' | ||
Two:В 'I'll see you next time.' | ||
One:В 'Sure. Bye.' | ||
</p> | ||
<button class="replace">REPLACE</button> | ||
</div> | ||
<form action="#" method="POST" class="some" id="myform"> | ||
<div> | ||
<label> | ||
Your name is ... <br> | ||
<input type="text" name="name" id="name" placeholder="Nikita"> | ||
</label> | ||
</div> | ||
<div> | ||
<label> | ||
Your number phone is ... <br> | ||
<input type="text" name="phone" id="phone" placeholder="89507500744"> | ||
</label> | ||
</div> | ||
<div> | ||
<label> | ||
Your email is ... <br> | ||
<input type="text" name="email" id="email" placeholder="[email protected]"> | ||
</label> | ||
</div> | ||
<button id="val-btn">Submit</button> | ||
</form> | ||
<script src="./form.js"></script> | ||
<script src="./replacer.js"></script> | ||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
let block = document.querySelector('.text'); | ||
document.querySelector('.replace').addEventListener('click',()=>{ | ||
block.textContent = block.textContent.replace(/\B'|'\B/g,'"'); | ||
block.style.color = 'green'; | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1 и 2 задания реализованя верно |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.text{ | ||
border-bottom: 4px solid black; | ||
} | ||
.error-msg{ | ||
color: red; | ||
margin: 10px 0; | ||
} | ||
.valid{ | ||
border: 2px solid green; | ||
} | ||
.invalid{ | ||
border: 2px solid red; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
По описанной в комментарии проблеме - вот тут беда у вас, нет селектора перед названием класса
querySelector(
.${Validator.errorClass}
)Из-за этого и работает неправильно