How to create Input Field for fixed numeric value? - html

I want to create a simple html input field where, for a specific numeric code, the continue/submit button will work.
For example, the submit button will go to its destination url, only if the input value is "1234". If the input value is not '1234' then the submit button will not proceed to next step.
Can anyone help?
Here the sollution i found. Big thanks to themoonroy.
https://github.com/Themoonroy/Basic-functions-code.git

test this code
document.getElementById("sub").addEventListener('click', ()=>{
var num_ = document.getElementById("num")
const validate = document.querySelector('#num + span.validate');
let pattern = /^([1234]{4})$/;
if(num_.value === ''){
num_.setAttribute('required','required')
}
else if(pattern.test(num_.value)){
num_.removeAttribute('required')
validate.textContent = "valid value"
}
else{
num_.removeAttribute('required')
num_.value = ''
validate.textContent = "invalid value !"
}
})
h1 {
text-align: center
}
input[type=number],
input[type=email],
select {
width: 100%;
padding: 12px;
margin: 8px 0;
display: inline-block;
border: 1px solid black;
border-radius: 4px;
box-sizing: border-box;
text-align: center;
}
input[type=submit] {
width: 25%;
background-color: #D39D10;
color: black;
padding: 14px;
margin: 20px 250px;
border: none;
border-radius: 4px;
cursor: pointer;
text-align: center;
}
input[type=submit]:hover {
background-color: green;
}
input:invalid {
border: 2px dashed red;
}
input:invalid:required {
background-image: linear-gradient(to right, pink, lightgreen);
}
input:valid {
border: 2px solid black;
}
<div class="ourform">
<form action="/">
<label for="name">number</label>
<input type="number" id="num" name="num" placeholder="Your number...">
<span class="validate" aria-live="polite"></span>
<input type="submit" value="Submit" id="sub">
</form>
</div>

Related

Html side by side select (with different number of columns)

I have a select where the user is supposed to choose a medicine for a specific day (the amount of days is selected by the user with a maximum of 7 days and a minimum of 1 day). Now depending on the amount of days that the user selects I want to show those many columns with my Select dropdown.
body {
width: 500px;
margin: 0 auto;
padding: 50px;
}
div.elem-group {
margin: 20px 0;
}
div.elem-group.inlined {
width: 49%;
display: inline-block;
float: left;
margin-left: 1%;
}
label {
display: block;
font-family: 'Nanum Gothic';
padding-bottom: 10px;
font-size: 1.25em;
}
input, select, textarea {
border-radius: 2px;
border: 2px solid #777;
box-sizing: border-box;
font-size: 1.25em;
font-family: 'Nanum Gothic';
width: 100%;
padding: 10px;
}
div.elem-group.inlined input {
width: 95%;
display: inline-block;
}
textarea {
height: 250px;
}
hr {
border: 1px dotted #ccc;
}
button {
height: 50px;
background: orange;
border: none;
color: white;
font-size: 1.25em;
font-family: 'Nanum Gothic';
border-radius: 4px;
cursor: pointer;
}
button:hover {
border: 2px solid black;
}
.btn-fetch{
width: 120%;
padding: 14px 20px;
margin: 8px 5px;
border: none;
border-radius: 4px;
cursor: pointer;
background-color: #3498DB;
color: white;
}
<form #datesForm = "ngForm" (ngSubmit)="checkDates(datesForm.value)">
<div class="elem-group inlined">
<label>First Day Of Your Plan</label>
<input type="date" name="firstDate" required>
</div>
<div class="elem-group inlined">
<label>Last Day Of Your Plan</label>
<input type="date" name="lastDate" required>
</div>
<button class="btn-fetch" (click)="checkDates(datesForm.value)">Confirm Dates</button>
<div class="elem-group" >
<label>Select A Plan Number </label>
<select name="planId" id="deviceoption" (click)="fetchPlans()" required>
<option type=placeholder>Choose a number from the List</option>
</select>
<br><br>
<select name="meds" required>
<option value="">Choose a a Medicine</option>
<option value="medsName"></option>
</select>
</div>
<button type="submit">Save the Plan</button>
</form>
For example if the user selects 5 days I want the "Choose Medicine" to appear 5 times, if the user selects 7 days I want it to appear 7 times. Any tips on how to to this?
To do what you want you need to use JavaScript. First of all you have to calculate the difference in days between the two dates, after which you just need to add as many options as there are days calculated.
// Define the function to check if a date is valid
function isValidDate(date) {
let d = new Date(date);
return !isNaN(d.getTime());
}
function onDateChange() {
// Get the input elements
let firstDate = document.getElementById("first-date");
let lastDate = document.getElementById("last-date");
// Get the select element
let medsOption = document.getElementById("meds-options");
// Check if both input values are valid dates
if (!isValidDate(firstDate.value) || !isValidDate(lastDate.value)) {
return;
}
// Convert the input values to Date objects
let date1Object = new Date(firstDate.value);
let date2Object = new Date(lastDate.value);
// Calculate the difference in milliseconds
let difference = date2Object - date1Object;
// Convert milliseconds to days
let days = difference / (1000 * 60 * 60 * 24);
// Clear any existing options
medsOption.innerHTML = "";
// Loop through the number of days
for (let i = 0; i < days; i++) {
// Create a new option element
let option = document.createElement("option");
// Set the value and text of the option
option.value = i + 1;
option.text = "Choose a Medicine";
// Append the option to the select element
medsOption.appendChild(option);
}
}
let firstDate = document.getElementById("first-date");
let lastDate = document.getElementById("last-date");
// Add an event listener to the input elements
firstDate.addEventListener("change", onDateChange);
lastDate.addEventListener("change", onDateChange);
body {
width: 500px;
margin: 0 auto;
padding: 50px;
}
div.elem-group {
margin: 20px 0;
}
div.elem-group.inlined {
width: 49%;
display: inline-block;
float: left;
margin-left: 1%;
}
label {
display: block;
font-family: 'Nanum Gothic';
padding-bottom: 10px;
font-size: 1.25em;
}
input, select, textarea {
border-radius: 2px;
border: 2px solid #777;
box-sizing: border-box;
font-size: 1.25em;
font-family: 'Nanum Gothic';
width: 100%;
padding: 10px;
}
div.elem-group.inlined input {
width: 95%;
display: inline-block;
}
textarea {
height: 250px;
}
hr {
border: 1px dotted #ccc;
}
button {
height: 50px;
background: orange;
border: none;
color: white;
font-size: 1.25em;
font-family: 'Nanum Gothic';
border-radius: 4px;
cursor: pointer;
}
button:hover {
border: 2px solid black;
}
.btn-fetch{
width: 120%;
padding: 14px 20px;
margin: 8px 5px;
border: none;
border-radius: 4px;
cursor: pointer;
background-color: #3498DB;
color: white;
}
<form #datesForm = "ngForm" (ngSubmit)="checkDates(datesForm.value)">
<div class="elem-group inlined">
<label>First Day Of Your Plan</label>
<input id="first-date" type="date" name="firstDate" required>
</div>
<div class="elem-group inlined">
<label>Last Day Of Your Plan</label>
<input id="last-date" type="date" name="lastDate" required>
</div>
<button id="confirm-dates-button" class="btn-fetch" (click)="checkDates(datesForm.value)">Confirm Dates</button>
<div class="elem-group" >
<label>Select A Plan Number </label>
<select name="planId" id="deviceoption" (click)="fetchPlans()" required>
<option type=placeholder>Choose a number from the List</option>
</select>
<br><br>
<select id="meds-options" name="meds" required>
<option value="">Choose a a Medicine</option>
<option value="medsName"></option>
</select>
</div>
<button type="submit">Save the Plan</button>
</form>

html date input without the date picker

I have a simple date input
<input type="date" id="sign-up-dob" class="sign-inputs" max="2999-12-31"></input>
It looks like this:
How would i get rid of the arrows and stuff to the right that open the date picker. I just want it so you can type the date with validation, thanks.
Just use the pattern attribute on a text input:
input:invalid {
color: red;
}
[type="date"]::-webkit-inner-spin-button {
display: none;
}
[type="date"]::-webkit-calendar-picker-indicator {
display: none;
}
<label>Input Date (YYYY-MM-DD):
<input type="text" pattern="[0-9]{4}-[0-9]{2}-[0-9]{2}" />
</label>
<input type="date" />
http://jsfiddle.net/trixta/cc7Rt/ For Reference
webshim.setOptions('forms-ext', {
replaceUI: 'auto',
types: 'date',
date: {
startView: 2,
inlinePicker: true,
classes: 'hide-inputbtns'
}
});
webshim.setOptions('forms', {
lazyCustomMessages: true
});
//start polyfilling
webshim.polyfill('forms forms-ext');
//only last example using format display
$(function () {
$('.format-date').each(function () {
var $display = $('.date-display', this);
$(this).on('change', function (e) {
//webshim.format will automatically format date to according to webshim.activeLang or the browsers locale
var localizedDate = webshim.format.date($.prop(e.target, 'value'));
$display.html(localizedDate);
});
});
});
.hide-replaced.ws-inputreplace {
display: none !important;
}
.input-picker .picker-list td > button.othermonth {
color: #888888;
background: #fff;
}
.ws-inline-picker.ws-size-2, .ws-inline-picker.ws-size-4 {
width: 49.6154em;
}
.ws-size-4 .ws-index-0, .ws-size-4 .ws-index-1 {
border-bottom: 0.07692em solid #eee;
padding-bottom: 1em;
margin-bottom: 0.5em;
}
.picker-list.ws-index-2, .picker-list.ws-index-3 {
margin-top: 3.5em;
}
div.ws-invalid input {
border-color: #c88;
}
.ws-invalid label {
color: #933;
}
div.ws-success input {
border-color: #8c8;
}
form {
margin: 10px auto;
width: 700px;
min-width: 49.6154em;
border: 1px solid #000;
padding: 10px;
}
.form-row {
padding: 5px 10px;
margin: 5px 0;
}
label {
display: block;
margin: 3px 0;
}
.form-row input {
width: 220px;
padding: 3px 1px;
border: 1px solid #ccc;
box-shadow: none;
}
.form-row input[type="checkbox"] {
width: 15px;
}
.date-display {
display: inline-block;
min-width: 200px;
padding: 5px;
border: 1px solid #ccc;
min-height: 1em;
}
.show-inputbtns .input-buttons {
display: inline-block;
}
<form action="#" class="ws-validate">
<h2>1 Calendars without visible input</h2>
<div class="form-row">
<input type="date" class="hide-replaced" />
</div>
<div class="form-row">
<input type="submit" />
</div>
</form>
<hr />

Making a bootstrap input clickable with a font-awesome icon in it

I have a date input field, and a font awesome icon on top of it. The look is correct, but I can't click on the input when the mouse in on top of the icon. I've tried to fix this using z-index, but it's not working.
Here's what it looks like:
HTML
<div class="form-group inline-block Criteria__datePickerDiv">
<input type="text" name="dob" id="datepicker" placeholder="Birth Date" class="Criteria__datePicker" value=" {{ old($user->seekerProfile->dob->format('Y-m-d')) }}">
</div>
<span class="Criteria__calendar">
<i class="fa fa-calendar"></i>
</span>
CSS
.Criteria__datePicker {
border: none;
border-bottom: 3px solid $gray-light;
font-size: 20px;
text-shadow: 0 0 0 $gray-light;
color: transparent;
font-weight: 600;
width: 150px;
padding-right: 5px;
margin-left: 15px;
&:focus {
outline: none
}
}
.Criteria__datePicker:hover {
cursor: pointer;
}
.Criteria__datePicker:focus {
outline: none;
}
.Criteria__datePickerDiv {
z-index: 1;
}
.Criteria__calendar {
position: relative;
left: -15px;
font-size: 22px;
color: $brand_green;
z-index: 0;
}
Using the default Bootstrap styles, you can get close to what you're doing with an input group (example):
HTML:
<div class="buffer">
<div class="input-group">
<input class="form-control" aria-describedby="basic-addon2" type="text">
<span class="input-group-addon" id="basic-addon2">
<i class="glyphicon glyphicon-calendar"></i>
</span>
</div>
</div>
CSS:
.buffer
{
margin: 1em;
width: 200px;
}
.buffer .input-group input
{
border-right: none;
}
.buffer .input-group .input-group-addon
{
background: #fff;
border-left: none;
}
If you're going for a borderless style, you can get even closer:
.buffer
{
margin: 1em;
width: 200px;
}
.buffer .input-group
{
border: none;
}
.buffer .input-group input
{
border-right: none;
border: none;
border-bottom: solid 1px #d5d5d5;
box-shadow: none;
border-radius: 0;
}
.buffer .input-group .input-group-addon
{
background: #fff;
border: none;
border-bottom: solid 1px #d5d5d5;
border-radius: 0;
}
.buffer is simply a container/class I added to contain the input group - you can safely remove that.

Stop hovering over input label from activing the input's hover styles when for...id is provided

I'm not sure if all browsers do this but if I provide a for attribute on a label that corresponds to an input's id, this makes hovering over the label trigger the input's hover styles which is undesirable in my case. Is there any way to stop this behavior while still having a form accessible to screen readers?
.field label {
display: block;
margin: 0 0 0.5em 0;
}
.field input {
background: white;
border: 1px solid #999;
border-radius: 0px;
color: black;
display: inline-block;
padding: 0.5em 0.7em
}
.field input:hover {
background: #efefff;
border-color: #333;
}
<div class="field">
<label for="myInput">Hover over this label:</label>
<input id="myInput" type="text">
</div>
You can use pointer-events:none; to disable hover effect for any element.
.field label {
display: block;
margin: 0 0 0.5em 0;
pointer-events:none;
}
.field input {
background: white;
border: 1px solid #999;
border-radius: 0px;
color: black;
display: inline-block;
padding: 0.5em 0.7em
}
.field input:hover {
background: #efefff;
border-color: #333;
}
<div class="field">
<label for="myInput">Hover over this label:</label>
<input id="myInput" type="text">
</div>

Styling the input type="file". How do I display the file path?

I have been trying to style an input type="file" field.
My button is styled but I can't seem to figure out how to get the filepath/file to show when the user selects the file to upload.
Can anyone out there help?
.file-upload {
overflow: hidden;
display: inline-block;
position: relative;
vertical-align: middle;
text-align: center;
color: #fff;
border: 2px solid #707070;
background: #A0A0A0;
-moz-border-radius: 8px;
-webkit-border-radius: 8px;
border-radius: 8px;
text-shadow: #000 1px 1px 4px;
cursor: pointer;
}
.file-upload:hover {
background: #2FA2FF;
}
.file-upload.focus {
outline: 2px solid yellow;
}
.file-upload input {
position: absolute;
top: 0;
left: 0;
margin: 0;
font-size: 12px;
opacity: 0;
filter: alpha(opacity=0);
z-index: -1;
}
.file-upload span {
position: absolute;
top: 0;
left: 0;
display: inline-block;
padding-top: .45em;
}
.file-upload {
height: 38px;
}
.file-upload,
.file-upload span {
width: 160px;
}
.file-upload-status {
margin-left: 10px;
vertical-align: middle;
padding: 7px 11px;
font-weight: bold;
font-size: 16px;
color: #888;
background: #f8f8f8;
border: 3px solid #ddd;
}
<form action="" method="POST" enctype="multipart/form-data">
<div class="fileupload-buttonbar">
<label class="file-upload"><span>Upload....</span><input name="uploadfile" type="file"> </label>
</div>
</form>
Add a change event to the input field, and then just get it's .value.
Example (using jQuery):
$('input[name="uploadfile"]').change(function(){
var fileName = $(this).val();
alert(fileName);
});
DEMO: http://jsfiddle.net/hjNEC/2/
EDIT: Since the input field is hidden, and the file name is part of that, you're gonna have to display fileName on the page yourself.
You can create a new div to show the file path, and use Javascript in the onchange event to update the path displayed in the div whenever the user selects a file.
<form action="" method="POST" enctype="multipart/form-data">
<div class="fileupload-buttonbar">
<input type="file" name="uploadfile" id="uploadfile" style="display:none" onchange="file_path_display.innerHTML=uploadfile.value"/>
<span class="file-upload" onclick="uploadfile.click()" ondragdrop="uploadfile.dragdrop()">Upload....</span>
<div id="file_path_display"></div>
</div>
</form>