Display image cropped notification on side of a button - html

I'm working with ReactJS and this success notification thing is not working as expected. When I crop the image and click on Confirm Crop button as shown in image below, I get the Loading loader and after the image is cropped it shows Image Saved! notification below the Confirm Crop button. But I want the Loading and Image Saved on side of the button, someone else worked on this before me and I am unable to solve this. What could fix the problem?
This is the form I'm working on below:
return (
<form className="form-horizontal" ref="form" onSubmit={this.handleForm}>
<fieldset>
<legend>
{this.state.success === true ? (
this.props.history.push(`/${serviceId}`)
) : this.state.success === false ? (
<Alert bsStyle="danger">
<strong>An error occured!</strong>
<ol>
{this.state.errorMessages.map((err, index) => (
<li key={index}>{err.message}</li>
))}
</ol>
</Alert>
) : (
""
)}
</legend>
<div className="row-fluid">
<div className="span5">
<div
className={
this.state.invalid.name === true
? "control-group error"
: "control-group"
}
>
<label className="control-label" htmlFor="name">
Name: <i className="required">*</i>
</label>
<div className="controls">
<input
type="text"
required
id="name"
defaultValue={this.state.form.name}
name="name"
onChange={this.handleState}
/>
<span className="help-inline">Field required</span>
</div>
</div>
<div
className={
this.state.invalid.image === true
? "control-group error"
: "control-group"
}
>
<label className="control-label" htmlFor="image">
Image: <i className="required">*</i>
</label>
<div className="controls">
<input
type="file"
name="image"
defaultValue={this.state.form.image}
onChange={this.handleState}
accept="image/gif, image/png, image/jpeg, image/jpg"
required
/>
<span className="help-inline">File Type: png, gif, jpg</span>
<div>
<ReactCrop
src={
this.state.companyImage === null
? ""
: this.state.companyImage
}
crop={this.state.crop}
onImageLoaded={this.handleImageLoaded.bind(this)}
onComplete={this.handleOnCropComplete.bind(this)}
onChange={this.handleOnCropChange.bind(this)}
keepSelection={true}
/>
</div>
{this.state.croppedImageUrl && (
<img alt="Crop" src={this.state.croppedImageUrl} />
)}
<br />
{this.state.croppedImageUrl ? (
<div>
<button
className="btn btn-primary"
type="button"
onClick={this.handleState}
>
Confirm Crop
</button>
</div>
) : null}
</div>
</div>
{this.state.imageFetching && (
<div className="controls">
<p className="imageWait">Loading...</p>
</div>
)}
{this.state.showImageSuccess && (
<div className="controls">
<p style={{ color: "green" }}>Image Saved! </p>
</div>
)}
<div
className={
this.state.invalid.address
? "control-group error"
: "control-group"
}
>
<label className="control-label" htmlFor="address">
Address <i className="required">*</i>
</label>
<div className="controls">
<textarea
rows="4"
required
cols="20"
id="address"
name="address"
onChange={this.handleState}
defaultValue={this.state.form.address}
/>
<span className="help-inline">Field required</span>
</div>
</div>
<div
className={
this.state.invalid.telephone
? "control-group error"
: "control-group"
}
>
<label className="control-label" htmlFor="telephone">
Telephone: <i className="required">*</i>
</label>
<div className="controls">
<input
type="number"
step="any"
required
name="telephone"
defaultValue={this.state.form.telephone}
onChange={this.handleState}
/>
<span className="help-inline">Field required</span>
</div>
</div>
<div
className={
this.state.invalid.city === true
? "control-group error"
: "control-group"
}
>
<label className="control-label" htmlFor="city">
City: <i className="required">*</i>
</label>
<div className="controls">
<input
type="text"
required
id="city"
defaultValue={this.state.form.city}
name="city"
onChange={this.handleState}
/>
<span className="help-inline">Field required</span>
</div>
</div>
<div
className={
this.state.invalid.country === true
? "control-group error"
: "control-group"
}
>
<label className="control-label" htmlFor="country">
Country: <i className="required">*</i>
</label>
<div className="controls">
<input
type="text"
required
id="country"
defaultValue={this.state.form.country}
name="country"
onChange={this.handleState}
/>
<span className="help-inline">Field required</span>
</div>
</div>
<div className="row-fluid">
<div className="span12">
<button
className={disabledColor}
type="submit"
disabled={this.state.disabled}
ref={button => {
this.submitButton = button;
}}
>
Submit
</button>
</div>
</div>
</div>
</div>
</fieldset>
</form>
);
How it looks right now:
The "Image Saved!" notification also appears in the same place as Loading as evident from code above, I need them on the side of the button.
This link provides the entire file and css associated with it that I'm working: https://gist.github.com/BikalNepal/0fe035e8845a5bb92c477abd9c003a50
CSS: https://gist.github.com/BikalNepal/73a3db6127ebda4b5489be8df3143d43

You need to re-structure you react element and that's all.
{this.state.croppedImageUrl ? (
<div className="flexContainer">
<button
className="btn btn-primary"
type="button"
onClick={this.handleState}
>
Confirm Crop
</button>
{this.state.imageFetching && (
<div className="controls">
<p className="imageWait">Loading...</p>
</div>
)}
{this.state.showImageSuccess && (
<div className="controls">
<p style={{ color: "green" }}>Image Saved! </p>
</div>
)}
</div>
) : null}
NOTE: All what I've done is: wrapped the elements that need to share same horizontal space, in one parent div.
And in the css file introduce a class:
.flexContainer {
display: flex;
justify-content: space-between;
align-items: center;
}
This might lead to lot of spacing between your button and notification. If so, try adding max-width: requiredValue; in the definition of the flexContainer class.

Related

Closing Hamburger menu in React

i'm trying to close the hamburger menu onClick with react, but so far have no results :( Read a lot of similar questions here, but everyone html is different and none of the answers worked for me :( Here's the code, i know it should be done with with useState, but how can i do it ? It's the first condition, the second is just a search input for the start page
return (
<>
{city ?
<nav>
<input id="nav-toggle" type="checkbox" />
<div className="nav-input">
<form method='POST' type="text" className='form' onSubmit={searchLocation}>
<input className="form-input" name='city' placeholder='Enter your location ...' />
<button type="submit" class="search-button">
<img src={search} />
</button>
</form>
</div>
<ul className="links">
<li><NavLink to="/now" style={({ isActive }) =>
isActive ? active : undefined
}>Now</NavLink></li>
<li><NavLink to="/hourly" style={({ isActive }) =>
isActive ? active : undefined
}>Hourly</NavLink></li>
<li><NavLink to="/daily" style={({ isActive }) =>
isActive ? active : undefined
}>Daily</NavLink></li>
</ul>
<label htmlFor="nav-toggle" className="icon-burger">
<div className="line"></div>
<div className="line"></div>
<div className="line"></div>
</label>
{city ?
<div className='city-name'>
<p>weather at: </p>
<h4>{city}</h4>
</div>
: null}
</nav>
:
<>
<div className='nav-start-page'>
<div>
<h3>Get Your Forecast</h3>
</div>
<div>
<Link className='location-link' to="/location">
<img src={location} />
</Link>
</div>
<div>
<form method='POST' type="text" onSubmit={searchLocation}>
<input className="form-input" name='city' placeholder='Enter your location ...' />
<button type="submit" class="search-button">
<img src={search} />
</button>
</form>
</div>
</div>
</>
}
</>
);
};
Add a click event on hamburger menu and set menu list hidden by default from css
i.e; visiblity: hidden. And on menu click function get menu list div by id from js and set their css visiblity: visible
Use useState and a callback function to toggle the hamburger menu onClick.
Try this:
const [isOpen, setIsOpen] = useState(false);
return (
<>
{city ?
<nav>
<input id="nav-toggle" type="checkbox" onClick={() => setIsOpen(!isOpen)} />
<div className="nav-input">
<form method='POST' type="text" className='form' onSubmit={searchLocation}>
<input className="form-input" name='city' placeholder='Enter your location ...' />
<button type="submit" class="search-button">
<img src={search} />
</button>
</form>
</div>
{isOpen && <ul className="links">
<li><NavLink to="/now" style={({ isActive }) =>
isActive ? active : undefined
}>Now</NavLink></li>
<li><NavLink to="/hourly" style={({ isActive }) =>
isActive ? active : undefined
}>Hourly</NavLink></li>
<li><NavLink to="/daily" style={({ isActive }) =>
isActive ? active : undefined
}>Daily</NavLink></li>
</ul>}
<label htmlFor="nav-toggle" className="icon-burger">
<div className="line"></div>
<div className="line"></div>
<div className="line"></div>
</label>
{city ?
<div className='city-name'>
<p>weather at: </p>
<h4>{city}</h4>
</div>
: null}
</nav>
:
<>
<div className='nav-start-page'>
<div>
<h3>Get Your Forecast</h3>
</div>
<div>
<Link className='location-link' to="/location">
<img src={location} />
</Link>
</div>
<div>
<form method='POST' type="text" onSubmit={searchLocation}>
<input className="form-input" name='city' placeholder='Enter your location ...' />
<button type="submit" class="search-button">
<img src={search} />
</button>
</form>
</div>
</div>
</>
}
</>
);
};

How to set the password filed inline (UI issue)?

I am building a signup form and encountered a UI issue.
I want two things to be done:
Confirm Password label should be in the one same line i.e. inline
eye icon should be inside the password input.
I have this currently
I want this
The first point is already explained.
For the second point I want below password field with # (replaced with eyeicon) at the end of the field.
code
This is just UI issue , so you can skip to the backend code. I have used inbuilt bootstrap -classes.
import { useNavigate } from "react-router-dom";
const SignupPage = (props) => {
const navigate = useNavigate();
const [showPassword, setShowPassword] = useState(false);
const [showConfmPassword, setShowConfmPassword] = useState(false);
const goToLogin = () => {
navigate("/login");
};
const [credentials, setCredentials] = useState({
name: "",
email: "",
password: "",
confmpassword: "",
role: "guest",
forgetQues: "",
forgetAns: "",
});
const onChange = (e, key) => {
setCredentials((prevCredentials) => ({
...prevCredentials,
[key]: e.target.value,
}));
//console.log(credentials);
};
const handleSubmit = async (e) => {
e.preventDefault();
const response = await fetch("http://localhost:5000/api/signup", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
name: credentials.name,
email: credentials.email,
password: credentials.password,
role: credentials.role,
forgetQues: credentials.forgetQues,
forgetAns: credentials.forgetAns,
}),
});
const json = await response.json();
//console.log(json);
if(json.success === true) {
localStorage.setItem('token', json.authToken);
navigate("/");
props.showAlert("User Registered Successfully !","info");
}
else {
props.showAlert("Invalid Credentials","danger");
}
};
function togglePasswordVisibilty (){
setShowPassword(!showPassword ? true:false)
}
function toggleConfmPasswordVisibilty (){
setShowConfmPassword(!showConfmPassword ? true:false)
}
return (
<>
<div className="container my-3">
<div id="loginbody">
<div className="mt-3">
<h2 className="my-3 display-3">Create your account here </h2>
<form className="login-form p-5" onSubmit={handleSubmit}>
<div className="mb-3">
<label htmlFor="name" className="form-label">
Name
</label>
<input
type="text"
className="form-control"
id="name"
name="name"
value={credentials.name}
onChange={(e) => onChange(e, "name")}
aria-describedby="emailHelp"
/>
</div>
{/* --------------- */}
<div className="mb-3">
<label htmlFor="email" className="form-label">
Email{" "}
</label>
<input
type="email"
className="form-control"
id="email"
name="email"
value={credentials.email}
onChange={(e) => onChange(e, "email")}
aria-describedby="emailHelp"
/>
</div>
<div className="mb-3">
<div className="pass-wrapper" style={{display:"flex",alignItems:"center"}}>
<label htmlFor="password" className="form-label">
Password
</label>
<input
type={showPassword ? "text":"password"}
className="form-control mx-3"
id="password"
name="password"
minLength={5}
value={credentials.password}
onChange={(e) => onChange(e, "password")}
required
/>
<i className={ showPassword ? "fas fa-eye-slash mx-2":"fas fa-eye mx-2"} title={ showPassword?"Hide Password":"Show Password"} onClick={togglePasswordVisibilty}></i>
</div>
</div>
<div className="mb-3">
<div className="pass-wrapper" style={{display:"flex",alignItems:"center"}}>
<label htmlFor="confmpassword" className="form-label">
Confirm Password
</label>
<input
type={showConfmPassword ? "text":"password"}
className="form-control mx-3"
id="confmpassword"
name="confmpassword"
value={credentials.confmpassword}
onChange={(e) => onChange(e, "confmpassword")}
minLength={5}
required
/>
<i className={ showConfmPassword ? "fas fa-eye-slash mx-2":"fas fa-eye mx-2"} title={ showConfmPassword?"Hide Confirmed Password":"Show Confirmed Password"} onClick={toggleConfmPasswordVisibilty}></i>
</div>
</div>
<div className="mb-3 col-md">
<label htmlFor="role" className="form-label">
<strong>Role</strong>
</label>
<div className="form-check form-check-inline mx-4">
<input
className="form-check-input"
type="radio"
name="roleOptions"
id="role1"
value="admin"
onChange={(e) => onChange(e, "role")}
/>
<label className="form-check-label" htmlFor="role1">
Admin
</label>
</div>
<div className="form-check form-check-inline">
<input
className="form-check-input"
type="radio"
name="roleOptions"
id="role2"
value="client"
onChange={(e) => onChange(e, "role")}
/>
<label className="form-check-label" htmlFor="role2">
Client
</label>
</div>
<div className="form-check form-check-inline">
<input
className="form-check-input"
type="radio"
name="roleOptions"
id="role3"
value="guest"
onChange={(e) => onChange(e, "role")}
/>
<label className="form-check-label" htmlFor="role3">
Guest
</label>
</div>
</div>
<div className="mb-3 row">
<div className="form-floating col-6">
<select
className="form-select"
id="forgetQues"
name="forgetQues"
value={credentials.forgetQues}
aria-label="Floating label select example"
onChange={(e) => onChange(e, "forgetQues")}
>
<option>Open this select menu</option>
<option value="Favourite Sport">Favourite Sport</option>
<option value="Favourite Food">Favourite Food</option>
<option value="Favourite City To Visit">
Favourite City To Visit
</option>
</select>
<label htmlFor="forgetQues">Select Question</label>
</div>
<div className="col-6">
<div className="form-floating mb-3">
<input
type="text"
className="form-control"
id="forgetAns"
name="forgetAns"
value={credentials.forgetAns}
onChange={(e) => onChange(e, "forgetAns")}
/>
<label htmlFor="forgetAns">Answer</label>
</div>
</div>
</div>
<div className="d-grid gap-2 my-4 col-6 mx-auto">
<button type="submit" className="btn btn-success ">
SignUp
</button>
</div>
<hr />
<div className="mb-3 text-center">
<div id="emailHelp" className="form-text center my-3">
Already have an account ?
</div>
<div className="d-grid gap-2 my-3 col-6 mx-auto">
<button onClick={goToLogin} className="btn btn-success ">
Login Here!
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</>
);
};
export default SignupPage;
Answer to your first question : Give enough width to 'label' so that it gets fit in the same line .
Answer to second question : Wrap the input and eye icon in a div -->
remove the border and outline of input tag , give width as 100% --> Make the wrapper display:flex , align-items:center, border : 1px solid gray
Your code for the confirm password issue should somewhat look like this
`<div style={{border:1px solid "gray",
display:flex,
align-items:center;}} >
​<input
​type={showConfmPassword ? "text":"password"}
​className="form-control mx-3"
​id="confmpassword"
​name="confmpassword"
​value={credentials.confmpassword}
​onChange={(e) => onChange(e, "confmpassword")}
​minLength={5}
​required
style={{border:0,outline:none;width:100%;}}
​/>
​<i className={ showConfmPassword ?"fas fa-eye-slash mx-2"
:"fas fa-eye mx-2"} title={ showConfmPassword?"Hide
Confirmed Password":"Show Confirmed Password"} onClick=
{toggleConfmPasswordVisibilty}>
</i>
</div>`
Figured out the issue and used the above answer approach, below is the correct code.
import React, { useState } from "react";
import { useNavigate } from "react-router-dom";
const SignupPage = (props) => {
const navigate = useNavigate();
const [showPassword, setShowPassword] = useState(false);
const [showConfmPassword, setShowConfmPassword] = useState(false);
const goToLogin = () => {
navigate("/login");
};
const [credentials, setCredentials] = useState({
name: "",
email: "",
password: "",
confmpassword: "",
role: "guest",
forgetQues: "",
forgetAns: "",
});
const onChange = (e, key) => {
setCredentials((prevCredentials) => ({
...prevCredentials,
[key]: e.target.value,
}));
//console.log(credentials);
};
const handleSubmit = async (e) => {
e.preventDefault();
const response = await fetch("http://localhost:5000/api/signup", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
name: credentials.name,
email: credentials.email,
password: credentials.password,
role: credentials.role,
forgetQues: credentials.forgetQues,
forgetAns: credentials.forgetAns,
}),
});
const json = await response.json();
//console.log(json);
if (json.success === true) {
localStorage.setItem("token", json.authToken);
navigate("/");
props.showAlert("User Registered Successfully !", "info");
} else {
props.showAlert("Invalid Credentials", "danger");
}
};
function togglePasswordVisibilty() {
setShowPassword(!showPassword ? true : false);
}
function toggleConfmPasswordVisibilty() {
setShowConfmPassword(!showConfmPassword ? true : false);
}
return (
<>
<div className="container my-3">
<div id="loginbody">
<div className="mt-3">
<h2 className="my-3 display-3">Create your account here </h2>
<form className="login-form p-5" onSubmit={handleSubmit}>
<div className="mb-3">
<label htmlFor="name" className="form-label">
Name
</label>
<input
type="text"
className="form-control"
id="name"
name="name"
value={credentials.name}
onChange={(e) => onChange(e, "name")}
aria-describedby="emailHelp"
/>
</div>
{/* --------------- */}
<div className="mb-3">
<label htmlFor="email" className="form-label">
Email{" "}
</label>
<input
type="email"
className="form-control"
id="email"
name="email"
value={credentials.email}
onChange={(e) => onChange(e, "email")}
aria-describedby="emailHelp"
/>
</div>
<div className="mb-3">
<div
className="pass-wrapper"
style={{ display: "flex", alignItems: "center" }}
>
<label
htmlFor="password"
className="form-label"
style={{ width: "200px" }}
>
Password
</label>
<div
style={{
border: "1px solid #ced4da",
display: "flex",
alignItems: "center",
width: "100%",
}}
>
<input
type={showPassword ? "text" : "password"}
className="form-control mx-3"
id="password"
name="password"
minLength={5}
value={credentials.password}
onChange={(e) => onChange(e, "password")}
style={{ outline: "none", border: 0 }}
required
/>
<i
className={
showPassword
? "fas fa-eye-slash mx-2"
: "fas fa-eye mx-2"
}
title={showPassword ? "Hide Password" : "Show Password"}
onClick={togglePasswordVisibilty}
></i>
</div>
</div>
</div>
<div className="mb-3">
<div
className="pass-wrapper"
style={{ display: "flex", alignItems: "center" }}
>
<label
htmlFor="confmpassword"
className="form-label"
style={{ width: "200px" }}
>
Confirm Password
</label>
<div
style={{
border: "1px solid #ced4da",
display: "flex",
alignItems: "center",
width: "100%",
}}
>
<input
type={showConfmPassword ? "text" : "password"}
className="form-control mx-3"
id="confmpassword"
name="confmpassword"
value={credentials.confmpassword}
onChange={(e) => onChange(e, "confmpassword")}
minLength={5}
required
style={{ border: 0, outline: "none" }}
/>
<i
className={
showConfmPassword
? "fas fa-eye-slash mx-2"
: "fas fa-eye mx-2"
}
title={
showConfmPassword
? "Hide Confirmed Password"
: "Show Confirmed Password"
}
onClick={toggleConfmPasswordVisibilty}
></i>
</div>
</div>
</div>
<div className="mb-3 col-md">
<label htmlFor="role" className="form-label">
<strong>Role</strong>
</label>
<div className="form-check form-check-inline mx-4">
<input
className="form-check-input"
type="radio"
name="roleOptions"
id="role1"
value="admin"
onChange={(e) => onChange(e, "role")}
/>
<label className="form-check-label" htmlFor="role1">
Admin
</label>
</div>
<div className="form-check form-check-inline">
<input
className="form-check-input"
type="radio"
name="roleOptions"
id="role2"
value="client"
onChange={(e) => onChange(e, "role")}
/>
<label className="form-check-label" htmlFor="role2">
Client
</label>
</div>
<div className="form-check form-check-inline">
<input
className="form-check-input"
type="radio"
name="roleOptions"
id="role3"
value="guest"
onChange={(e) => onChange(e, "role")}
/>
<label className="form-check-label" htmlFor="role3">
Guest
</label>
</div>
</div>
<div className="mb-3 row">
<div className="form-floating col-6">
<select
className="form-select"
id="forgetQues"
name="forgetQues"
value={credentials.forgetQues}
aria-label="Floating label select example"
onChange={(e) => onChange(e, "forgetQues")}
>
<option>Open this select menu</option>
<option value="Favourite Sport">Favourite Sport</option>
<option value="Favourite Food">Favourite Food</option>
<option value="Favourite City To Visit">
Favourite City To Visit
</option>
</select>
<label htmlFor="forgetQues">Select Question</label>
</div>
<div className="col-6">
<div className="form-floating mb-3">
<input
type="text"
className="form-control"
id="forgetAns"
name="forgetAns"
value={credentials.forgetAns}
onChange={(e) => onChange(e, "forgetAns")}
/>
<label htmlFor="forgetAns">Answer</label>
</div>
</div>
</div>
<div className="d-grid gap-2 my-4 col-6 mx-auto">
<button type="submit" className="btn btn-success ">
SignUp
</button>
</div>
<hr />
<div className="mb-3 text-center">
<div id="emailHelp" className="form-text center my-3">
Already have an account ?
</div>
<div className="d-grid gap-2 my-3 col-6 mx-auto">
<button onClick={goToLogin} className="btn btn-success ">
Login Here!
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</>
);
};
export default SignupPage;

Show element with input button only with css

I want to show an section when the checkbox is checked on another section, and show it with an animation from the top. I have the following code for the input that is in another section .
<div className="continue" id="first">
<button className="btn-continue">
Contratar Plano
<input type="checkbox" id="reveal-email" role="button"/>
</button>
</div>
<section className="plan-section" id="plan-section">
<div className="next">
<i class="arrow down"></i>
</div>
<div className="form-block">
<form className="form">
<div className="plan-form">
<div className="input-block">
<label htmlFor="name">Nome</label>
<input type="text" name="name" id="name" onChange={props.handleChange} required className="input" />
</div>
<div className="continue">
<button className="btn-continue" id="plan-continue" disabled={props.step.isLast()} onClick={props.next}>
<span className="btn-text">Contratar Plano</span>
<img className="check-btn" src={check} />
</button>
</div>
</div>
</form>
</div>
</section>
Also showing the section I need to show; this section has a default display:none.
Its a classic JS task. Use an onclick event to check if the checkbox is checked and then to change the section from display: none to display: block . Also Add an onclick event so that JS is triggered.
function showSection() {
var showSection = document.getElementById("reveal-email"),
planSection = document.getElementById("plan-section");
if (showSection.checked == true) {
planSection.style.display = "block";
} else {
planSection.style.display = "none";
}
}
#plan-section {
display: none;
}
<div className="continue" id="first">
<button className="btn-continue">Contratar Plano
<input type="checkbox" id="reveal-email" onclick="showSection()">
</button>
</div>
<section className="plan-section" id="plan-section">
<div className="next">
<i class="arrow down"></i>
</div>
<div className="form-block">
<form className="form">
<div className="plan-form">
<div className="input-block">
<label htmlFor="name">Nome</label>
<input type="text" name="name" id="name" onChange={props.handleChange} required className="input" />
</div>
<div className="continue">
<button className="btn-continue" id="plan-continue" disabled={props.step.isLast()} onClick={props.next}>
<span className="btn-text">Contratar Plano</span>
<img className="check-btn" src={check} />
</button>
</div>
</div>
</form>
</div>
</section>
One recommendation regarding your code:
<button className="btn-continue">
Contratar Plano
<input type="checkbox" id="reveal-email" role="button"></input>
</button>
It's not a good practice to group checkbox and some text into button, in HTML you can use label for that.
If JS solution is acceptable, you need to follow these steps:
Find your checkbox button and section in the DOM
Add event listener which will trigger callback function after each change of the checkbox state
In the callback function you need to trigger style for your section.
The full code is below:
var checkbox = document.getElementById('reveal-email');
var section = document.getElementById('plan-section');
checkbox.addEventListener('change', onChange)
function onChange() {
if (this.checked) {
section.style.display = "block";
} else {
section.style.display = "none";
}
}
<div className="continue" id="first">
<button className="btn-continue">
Contratar Plano
<input type="checkbox" id="reveal-email" role="button"/>
</button>
</div>
<section className="plan-section" id="plan-section" style="display:none">
<div className="next">
<i class="arrow down"></i>
</div>
<div className="form-block">
<form className="form">
<div className="plan-form">
<div className="input-block">
<label htmlFor="name">Nome</label>
<input type="text" name="name" id="name" onChange={props.handleChange} required className="input" />
</div>
<div className="continue">
<button className="btn-continue" id="plan-continue" disabled={props.step.isLast()} onClick={props.next}>
<span className="btn-text">Contratar Plano</span>
<img className="check-btn" src={check} />
</button>
</div>
</div>
</form>
</div>
</section>

[ng-bootstrap]: Open modal after calling api, ExpressionChangedAfterItHasBeenCheckedError

i'm using Angular, express (node).
I am opening a modal after validating the user's data at login (httpClient - express).
But when I open the modal (yes, the modal opens) I get an exception in the console:
ExpressionChangedAfterItHasBeenCheckedError:
Expression has changed after it was checked. Previous value:
'ng-untouched: true'. Current value: 'ng-untouched: false'.
Here is my basic code:
example.html
<ng-template #modalexample let-c="close" let-d="dismiss">
/** modal body **/
</ng-template>
form (ngSubmit)="f.form.valid && signin()" #f="ngForm" class="m-login__form m-form" action="">
<ng-template #alertSignin></ng-template>
<div class="form-group m-form__group">
<input class="form-control m-input" type="text" placeholder="Email" name="email" [(ngModel)]="model.email" #email="ngModel" autocomplete="off">
</div>
<div class="form-group m-form__group">
<input class="form-control m-input m-login__form-input--last" type="password" placeholder="Password" name="password" [(ngModel)]="model.password" #password="ngModel">
</div>
<div class="row m-login__form-sub">
<div class="col m--align-left">
<label class="m-checkbox m-checkbox--focus">
<input type="checkbox" name="remember" [(ngModel)]="model.remember" #remember="ngModel">
Remember me
<span></span>
</label>
</div>
<div class="col m--align-right">
<a href="javascript:;" id="m_login_forget_password" class="m-link">
Forget Password ?
</a>
</div>
</div>
<div class="m-login__form-action">
<button [disabled]="loading" [ngClass]="{'m-loader m-loader--right m-loader--light': loading}" id="m_login_signin_submit" class="btn btn-focus m-btn m-btn--pill m-btn--custom m-btn--air">
Sign In
</button>
</div>
</form>
And my component.ts
#ViewChild('modalexample', {read: TemplateRef}) modal: TemplateRef<any>;
signin() {
console.log("Signin")
this.modalService.open(this.content);
this.loading=true;
this._authUser.login(this.model.email, this.model.password).subscribe(
response=>{
if(!response.error){
this.loading=false;
}
else{
alert('Error');
}
this.loading=false;
},
error=>{
console.log(error)
this.loading=false;
}
)
}
How can I solve it?
Thank you :D

Validate date field

I am trying to disable the save button untill date is not picked. it is disabled but its not able to enbale untill i dont press any key from the keyboard.please tell me what i am doing wrong and thanks in advance.
<div class = "form-group" ng-class="{ 'has-error' : Form.fromTime.$invalid && !Form.fromTime.$pristine }">
<label for = "fromTime"> From Time:
<img src = "images/required.gif" alt = "Required" class = "required-star">
</label>
<div class='input-group date' id='fromTime' >
<input type='text' class="form-control" name="fromTime" ng-model = "fromTime" required />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
<p ng-show="Form.fromTime.$invalid && !Form.fromTime.$pristine" class="help-block">From Time is required.</p>
</div>
<button type="button" class="col-sm-2 btn btn-primary" ng-click="scheduleCall()" style="margin-left:10px;" ng-disabled="Form.$invalid"> Save </button>
change:
ng-disabled="Form.$invalid"
to:
ng-disabled="Form.fromTime.$invalid"
You have to use like below
ng-disabled="Form.fromTime.$invalid"
Formname: Form;
Input field name : fromTime;
Input field state: $invalid
If i understand your problem correctly, you need to use a date input.
Now save button will be disabled until a valid date is picked.
function Ctrl($scope) {
$scope.fromTime = '';
$scope.scheduleCall = function() {};
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.9/angular.min.js"></script>
<div ng-app>
<div ng-controller="Ctrl">
<form name="Form">
<div class="form-group"
ng-class="{ 'has-error' : Form.fromTime.$invalid && !Form.fromTime.$pristine }">
<label for="fromTime">From Time:</label>
<div class='input-group date' id='fromTime'>
<input type='date' class="form-control" name="fromTime" ng-model="fromTime" required />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
<p ng-show="Form.fromTime.$invalid && !Form.fromTime.$pristine"
style="font-size: 11px; color: red;">
From Time is required.
</p>
</div>
<button type="button" ng-click="scheduleCall()" ng-disabled="Form.$invalid">Save</button>
</form>
</div>
</div>