Html blank entry - html

I have a survey that requires the takers to complete all the fields but somehow I have blank entries in the output file for the columns "title2" and "dept2". I believe when they provide no answer in the blank spaces, it is shown as "{}". But these entries are completely blank which I cannot understand how. I was wondering if there is any general mistake that could give rise to this issue. The whole code is provided below. Thank you.
<p> </p>
<link crossorigin="anonymous" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" integrity="sha384- IS73LIqjtYesmURkDE9MXKbXqYA8rvKEp/ghicjem7Vc3mGRdQRptJSz60tvrB6+" rel="stylesheet" />
<meta content="width=device-width,initial-scale=1" name="viewport" />
<p> </p>
<section class="container" id="TranscriptionFromAnImage"><!-- Instructions -- >
<div class="row">
<div class="col-xs-12 col-md-12">
<div class="panel panel-primary"><a class="panel-heading"><strong>Table transcription instructions</strong> </a>
<p> </p>
<p><span style="font-family:arial,helvetica,sans-serif;">F</span><span style="font-family: arial, helvetica, sans-serif;">or each job (up to two) that this person has had since he/she received his/her </span><span style="font- family: arial, helvetica, sans-serif;">Ph.D.</span><span style="font-family: arial, helvetica, sans-serif;">, please copy and paste the related sections from this CV whenever possible:</span></p>
<ol style="font-size: 14px;">
<li>
<p><span style="font-family:arial,helvetica,sans-serif;">The institution for which he/she has worked</span></p>
</li>
<li>
<p><span style="font-family:arial,helvetica,sans-serif;">His/her department in the institution</span></p>
</li>
<li>
<p><span style="font-family:arial,helvetica,sans-serif;">The title of his/her job</span></p>
</li>
<li>
<p><span style="font-family:arial,helvetica,sans-serif;">Start year</span> </p>
</li>
<li>
<p><span style="font-family:arial,helvetica,sans-serif;">The year in which he/she left the job </span></p>
</li>
</ol>
<p>When some of this information is not present in the C.V. leave the related sections blank..</p>
<p>// AND if "Other" is an option, select "Other" and type "NA" in the blank space provided. If "Other" is not an option, only type "NA" in the blank space provided. <span style="font-family: arial, helvetica, sans-serif;">If the person has had only one job since getting his/her Ph.D., follow this procedure for the questions related to the second job. //</span></p>
<p>As a rule of thumb, if the start year of a job is specified but the end year is not, select "Ongoing" for the end year.</p>
<p>Please check the two links below as a reference.</p>
<div align="left"><font color="red">Link to the first example:link</font></div>
<div align="left"><font color="red">Link to the second example: link</font></div>
<div align="left"> </div>
</div>
</div>
</div>
<iframe height="1000" src="${pdf_url}" width="700"></iframe>
<div class="col-xs-12 col-sm-4 fields">
<div class="form-group"> </div>
<div class="form-group"><strong><font color="red">Questions related to the FIRST job after receiving Ph.D.</font></strong></div>
<div class="form-group"><label for="TranscriptionTexts">1. Copy and paste the name of the institution for which this person worked for</label><textarea class="form-control" cols="250" id="1st_inst" name="1st_inst" required="" rows="1"></textarea></div>
<p> </p>
<div class="form-group"><label for="TranscriptionTexts">2. Select the option "Economics department" if his/her job is at an economics department. Otherwise, select "Other" and copy and paste his department or division in the institution</label></div>
<div class="radio-inline"><label><input autocomplete="off" id="option1" name="dept1" required="" type="radio" value="econdept" /> Economics department</label></div>
<div class="radio"><label><input autocomplete="off" id="option2" name="dept1" required="" type="radio" value="other" />Other</label><textarea class="form-control" cols="250" id="1st_dept_other" name="1st_dept_other" rows="1"> </textarea></div>
<div class="form-group"> </div>
<div class="form-group"><label for="TranscriptionTexts">3. Select the title of this person's first job. If the title is neither "Assistant Professor" nor "Post-doc", select "Other" and copy and paste the title from the CV</label></div>
<div class="radio-inline"><label><input autocomplete="off" id="option1" name="title1" required="" type="radio" value="ap" /> Assistant professor </label> </div>
<div class="radio-inline"><label><input autocomplete="off" id="option2" name="title1" required="" type="radio" value="postdoc" />Post-doc</label></div>
<div class="radio"><label><input autocomplete="off" id="option3" name="title1" required="" type="radio" value="other" />Other</label><textarea class="form-control" cols="250" id="1st_title_other" name="1st_title_other" rows="1"></textarea></div>
<div class="form-group">
<p> </p>
<p><label class="group-label">4. Select the start year of this job from the drop-down menu below</label></p>
<input list="startyr1" name="startyr1" placeholder="Choose start year" /> <datalist id="startyr1"><option value="2017"></option><option value="2018"> </option><option value="NA"></option></datalist></div>
<div class="form-group">
<p> </p>
<p><label class="group-label">5. Select the end year of this job from the drop-down menu below. If still holding the position, select "Ongoing" from the menu.</label></p>
<input list="endyr1" name="endyr1" placeholder="Choose end year" /> <datalist id="endyr1"><option value="2017"></option><option value="2018"></option><option value="Ongoing"></option><option value="NA"></option></datalist></div>
<div class="form-group"> </div>
<div class="form-group"><strong><font color="red">Questions related to the SECOND job after receiving Ph.D.</font></strong></div>
<div class="form-group"><label for="TranscriptionTexts">6. </label><span style="font-weight: 700;">Copy and paste the name of the institution for which this person worked for</span><textarea class="form-control" cols="250" id="2nd_inst" name="2nd_inst" required="" rows="1"></textarea></div>
<div class="form-group"><label for="TranscriptionTexts">7. </label><span style="font-weight: 700;">Select the option "Economics department" if his/her job is at an economics department. Otherwise, select "Other" and copy and paste his department or division in the institution</span> </div>
**<div class="radio-inline"><label><input autocomplete="off" id="option1" name="dept2" required="" type="radio" value="econdept" /> Economics department </label></div>
<div class="radio"><label><input autocomplete="off" id="option2" name="dept2" required="" type="radio" value="other" />Other</label><textarea class="form- control" cols="250" id="2nd_dept_other" name="2nd_dept_other" rows="1"> </textarea></div>
<div class="form-group"> </div>
<div class="form-group"><label for="TranscriptionTexts">8. </label><span style="font-weight: 700;">Select the title of this person's first job. If the title is neither "Assistant Professor" nor "Post-doc", select "Other" and copy and paste the title from the CV</span></div>
<div class="radio-inline"><label><input autocomplete="off" id="option1" name="title2" required="" type="radio" value="ap" /> Assistant professor </label></div>
<div class="radio-inline"><label><input autocomplete="off" id="option2" name="title2" required="" type="radio" value="postdoc" />Post-doc</label></div>
<div class="radio"><label><input autocomplete="off" id="option3" name="title2" required="" type="radio" value="other" />Other</label><textarea class="form-control" cols="250" id="2nd_title_other" name="2nd_title_other" rows="1"></textarea></div>**
<div class="form-group">
<p> </p>
<p><label class="group-label">9. Choose the start year from the drop-down menu below</label></p>
<input list="startyr2" name="startyr2" placeholder="Choose start year" /> <datalist id="startyr2"><option value="2017"></option><option value="2018"></option><option value="NA"></option></datalist></div>
<div class="form-group">
<p><label class="group-label">10. Select the end year of this job from the drop-down menu below. If still holding the position, select "Ongoing" from the drop-down menu.</label></p>
<input list="endyr2" name="endyr2" placeholder="Choose end year" /> <datalist id="endyr2"><option value="2017"></option><option value="2018"></option><option value="NA"></option><option value="Ongoing"></option></datalist></div>
<!-- End Image Transcription Layout --><!-- Open internal style sheet -->
<style type="text/css">#collapseTrigger{ color:#fff; display: block; text-decoration: none; } #submitButton{ white-space: normal; } .image{ margin-bottom: 15px; } .group-label{ display: block; } .radio-inline>label{ font-weight: normal; }
</style>
<!-- Close internal style sheet --><!-- Please note that Bootstrap CSS/JS and JQuery are 3rd party libraries that may update their url/code at any time. Amazon Mechanical Turk (MTurk) is including these libraries as a default option for you, but is not responsible for any changes to the external libraries --><script src="https://code.jquery.com/jquery-3.1.0.min.js" integrity="sha256-cCueBR6CsyA4/9szpPfrX3s49M9vUU5BgtiJj06wt/s=" crossorigin="anonymous"></script><script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js" integrity="sha384-s1ITto93iSMDxlp/79qhWHi+LsIi9Gx6yL+cOKDuymvihkfol83TYbLbOw+W/wv4" crossorigin="anonymous"></script><script>
$(document).ready(function() {
// Instructions expand/collapse
var content = $('#instructionBody');
var trigger = $('#collapseTrigger');
content.hide();
$('.collapse-text').text('(Click to expand)');
trigger.click(function(){
content.toggle();
var isVisible = content.is(':visible');
if(isVisible){
$('.collapse-text').text('(Click to collapse)');
}else{
$('.collapse-text').text('(Click to expand)');
}
});
// end expand/collapse
});
</script></div>
</section>
<p> </p>

The entries may be more than one space which would not be an empty String.
You can use the following function to check if a String is null, empty, or only spaces:
function isNullOrEmpty(str){
return !str.trim().length;
}
<input id="testinput" type="text" onkeyup="checkEmpty()"/>
<br/>
<span id="result"></span>
<script>
var result = document.getElementById("result");
function isNullOrEmpty(str){
return !str.trim().length;
}
function checkEmpty(){
var input = document.getElementById("testinput").value;
if(isNullOrEmpty(input)){
result.innerHTML = "Empty string";
} else {
result.innerHTML = "Non-empty string";
}
}
</script>
Form with check to see if all fields are filled in:
<form id="thisForm">
<label for="username"><b>Username:</b></label><br/>
<input type="text" id="username">
<br/>
<label for="password"><b>Password:</b></label><br/>
<input type="password" id="password">
<br/>
<input type="button" value="Submit" onClick="validateForm()">
</form>
<span id="result"></span>
<script>
var result = document.getElementById("result");
function isNullOrEmpty(str){
return !str.trim().length;
}
function validateForm(){
result.innerHTML = "";
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
var passed = true;
if(isNullOrEmpty(username)){
result.innerHTML += "<p/><b style='color: red;'>Username can not be empty!</b>";
passed = false;
}
if(isNullOrEmpty(password)){
result.innerHTML += "<p/><b style='color: red;'>Password can not be empty!</b>";
passed = false;
}
if(passed){
document.getElementById("thisForm").style.display = "none";
result.innerHTML = "<h1>Form submitted successfully!</h1>";
}
}
</script>

Related

trying to display first and second form at second step

Here I have written a code for multistep form and every thing is working fine here. But here while we are at first step and if we click on next button then next step form will display so here I want to show first step form along with next step form. That means while we click next button from first step then next step should be with first form and second form
<div id="app">
<form>
<div v-if="step === 1">
<h1>Step One</h1>
<p>
<legend for="name">Your Name:</legend>
<input id="name" name="name" v-model="registration.name">
</p>
<p>
<legend for="email">Your Email:</legend>
<input id="email" name="email" type="email" v-model="registration.email">
</p>
<button #click.prevent="next()">Next</button>
</div>
<div v-if="step === 2">
<h1>Step Two</h1>
<p>
<legend for="street">Your Street:</legend>
<input id="street" name="street" v-model="registration.street">
</p>
<p>
<legend for="city">Your City:</legend>
<input id="city" name="city" v-model="registration.city">
</p>
<p>
<legend for="state">Your State:</legend>
<input id="state" name="state" v-model="registration.state">
</p>
<button #click.prevent="prev()">Previous</button>
<button #click.prevent="next()">Next</button>
</div>
<div v-if="step === 3">
<h1>Step Three</h1>
<p>
<legend for="numtickets">Number of Tickets:</legend>
<input id="numtickets" name="numtickets" type="number" v-model="registration.numtickets">
</p>
<p>
<legend for="shirtsize">Shirt Size:</legend>
<select id="shirtsize" name="shirtsize" v-model="registration.shirtsize">
<option value="S">Small</option>
<option value="M">Medium</option>
<option value="L">Large</option>
<option value="XL">X-Large</option>
</select>
</p>
<button #click.prevent="prev()">Previous</button>
<button #click.prevent="submit()">Save</button>
</div>
</form>
vue.js
const app = new Vue({
el:'#app',
data() {
return {
step:1,
registration:{
name:null,
email:null,
street:null,
city:null,
state:null,
numtickets:0,
shirtsize:'XL'
}
}
},
methods:{
prev() {
this.step--;
},
next() {
this.step++;
},
submit() {
alert('Submit to blah and show blah and etc.');
}
}
});
Since step is incremented on each next() call, you could change the conditional rendering to render when the step is at least some index:
<div v-if="step >= 1">...</div>
<div v-if="step >= 2">...</div>
<div v-if="step >= 3">...</div>
demo

HTML forms are a mystery

I am taking a Vue.js course and I just learned about forms and managing them(the code is down below). I don't understand how does the tag work. It's value is determined by the option value and the selected text is the text of that specific option? Also, I am confused when it comes to checkboxes and Vue. Why do the checkboxes need different "value"s when you use v-model on that checkbox? Why would I want to create a checkbox group (inputs with the same value for the name attribute)? I don't really understand how v-model works with forms and I would love to. Thanks in advance for the person that's taking time to help me.
The Code
<template>
<form #submit.prevent="submitForm">
<div class="form-control">
<label for="user-name">Your Name</label>
<input id="user-name" name="user-name" type="text" v-model="userName" />
</div>
<div class="form-control">
<label for="age">Your Age (Years)</label>
<input id="age" name="age" type="number" v-model.number="userAge" />
</div>
<div class="form-control">
<label for="referrer">How did you hear about us?</label>
<select id="referrer" name="referrer" v-model="referrer">
<option value="google">Google</option>
<option value="wom">Word of mouth</option>
<option value="newspaper">Newspaper</option>
</select>
{{ referrer }}
</div>
<div class="form-control">
<h2>What are you interested in?</h2>
<div>
<input id="interest-news" name="interest" value="news" type="checkbox" v-model="interests"/>
<label for="interest-news">News</label>
</div>
<div>
<input id="interest-tutorials" name="interest" value="tutorials" type="checkbox" v-model="interests"/>
<label for="interest-tutorials">Tutorials</label>
</div>
<div>
<input id="interest-nothing" name="interest" value="nothing" type="checkbox" v-model="interests"/>
<label for="interest-nothing">Nothing</label>
</div>
</div>
<div class="form-control">
<h2>How do you learn?</h2>
<div>
<input id="how-video" name="how" value="video" type="radio" v-model="how"/>
<label for="how-video">Video Courses</label>
</div>
<div>
<input id="how-blogs" name="how" value="blogs" type="radio" v-model="how"/>
<label for="how-blogs">Blogs</label>
</div>
<div>
<input id="how-other" name="how" value="other" type="radio" v-model="how"/>
<label for="how-other">Other</label>
</div>
</div>
<div class="form-control">
<input type="checkbox" id="confirm-terms" name="confirm-terms" v-model="confirm">
<label for="confirm-terms">Agree to terms of use?</label>
</div>
<div>
<button>Save Data</button>
</div>
<div class="form-control">
<select></select>
</div>
</form>
</template>
<script>
export default {
data() {
return {
userName: "",
userAge: null,
referrer: "newspaper",
interests: [],
how: null,
confirm: false
};
},
methods: {
submitForm() {
// console.log("Username: " + this.userName);
// this.userName = "";
// console.log("User age: ");
// console.log(this.userAge);
// console.log(31);
// this.userAge = null;
// console.log("Referrer: " + this.referrer);
// this.referrer = "wom";
// console.log("Checkboxes: ");
// console.log(this.interests);
console.log("Radio Buttons");
console.log(this.how);
this.interests = [];
this.how = null;
// console.log('Confirm? ');
// console.log(this.confirm);
// this.confirm = false;
},
},
};
</script>
v-model is syntactical sugar for :value and #change
Instead of <input v-model="name">, you could use
<input :value="name" #update:model-value="v => name=v"> which would have the same result.
Here is an example that perhaps belabors it a bit.
const app = Vue.createApp({
data() {
return {
name: ""
}
}
})
app.component('custom-input', {
props: ['modelValue'],
emits: ['update:modelValue'],
template: `
<input
:value="modelValue"
#input="$emit('update:modelValue', $event.target.value)"
>
`
})
app.mount("#app")
<script src="https://unpkg.com/vue#next/dist/vue.global.prod.js"></script>
<div id="app">
<custom-input :value="name" #update:model-value="v => name=v"></custom-input><br />
<custom-input v-model="name"></custom-input><br />
<input :value="name" #update:model-value="v => name=v"><br />
<input v-model="name"><br />
Name: {{name}}
</div>
More info in v3 docs here

How to change date format using JqueryUI based on timezone?

I have the code for date picker using JqueryUI, i want to use my timezone(SA region). The date format should be 'dd-mm-yy' But my UI on my text field is 01/08/2020. Is this correct format of doing this, kindly please assist to improve this better, thanks.
<!---DatePicker for startDate and endDate.
---->
<div class="d-flex justify-content-start">
<div class = "col-xl-10.5 col-lg-10.5 col-md-10 col-sm-10.5 col-10.5">
<div class="input-daterange input-group" id="datepicker">
<input type="text" class="input-sm form-control" name="from" placeholder="startdate"/>
<span class="input-group-addon">To</span>
<input type="text" class= "input-sm form-control" placeholder="enddate"/>
</div>
</div>
</div><br/>
// date functionality
$(document).ready(function(){
$('.input-daterange').datepicker({
dateFormat: "dd-mm-yy",
autoclose:true
});
});
I setup the following test using jQuery UI.
$(function() {
// date functionality
$.datepicker.setDefaults($.datepicker.regional["sa"]);
$('.input-daterange input').datepicker({
dateFormat: "dd-mm-yy"
});
});
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<div class="d-flex justify-content-start">
<div class="col-xl-10.5 col-lg-10.5 col-md-10 col-sm-10.5 col-10.5">
<div class="input-daterange input-group" id="datepicker">
<input type="text" class="input-sm form-control" name="from" placeholder="startdate" />
<span class="input-group-addon">To</span>
<input type="text" class="input-sm form-control" placeholder="enddate" />
</div>
</div>
</div>
<br/>
The $.datepicker.regional attribute holds an array of localizations, indexed by language code, with "" referring to the default (English). Each entry is an object with the following attributes: closeText, prevText, nextText, currentText, monthNames, monthNamesShort, dayNames, dayNamesShort, dayNamesMin, weekHeader, dateFormat, firstDay, isRTL, showMonthAfterYear, and yearSuffix.

HTML input required fields don´t work

I have one small web app for learning purposes, and I realised "required" attribute doesn´t work, and I can´t find why. It happens on many browsers, so I guess it is not a browser problem.
Things I tried:
Check <!DOCTYPE html> tag is included
Semi-closed the input tags (but deleted that since I have read here it could make some browsers to work in a wrong way).
Check no value attribute is included, since it could make the required attribute be useless
Just to test, put the input button out of the enclosing tags
The two forms seem to be properly closed
Links I looked:
HTML input required attribute not working for a field
html required tag doesn't work for form submission
textarea's "required" attribute doesn't work even though the value is empty
'Required' attribute not working
Required attribute doesn't work
And many others
My code:
index.php
<?php
session_start();
require_once('models/UsuarioPDO.php');
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="assets/css/form-styles.css">
<link rel="stylesheet" href="assets/css/styles.css">
<link rel="stylesheet" href="assets/css/cookies.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.8/css/all.css">
<!--jquery always bwfore bootsrap, sine bootsrap need it-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js" defer></script>
<link href="/bootstrap/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css" >
<script src="/bootstrap/js/bootstrap.min.js" defer></script>
<script src="controls/registerSubmit.js" defer></script>
<!------ Include the above in your HEAD tag ---------->
</head>
<body>
<?php
/*if there is the two cookies, we start the session with the user
who belog the data of that cookie*/
if(isset($_COOKIE["id_usuario_myreminder"]) && isset($_COOKIE["random_number_user_myreminder"]))
{
$usuarioAlogear= usuarioPDO::getUserWhenCookie($_COOKIE["id_usuario_myreminder"],$_COOKIE["random_number_user_myreminder"]);
$_SESSION["usuario"]=$usuarioAlogear;
}
/*if there is user logged in, back to main*/
if(isset($_SESSION["usuario"]))
{
header('Location:views/main.php');
exit;
}else
{/*if there is not logged user, show index components*/
/*is comes from registerUser.php but was not possible to insert the user due to repeated email,
we send a session variables here to make this page show a flag, then we destroy the session
to ensure it won´t appear again*/
if( (isset($_SESSION["mailrepetido"]))&&($_SESSION["mailrepetido"])==true )
{
?>
<div class="alert alert-danger" role="alert">
E Mail already exists for another user
</div>
<?php
session_destroy();
}
/*if login attempt was wrong, another flag*/
if( isset($_SESSION["wrongLogIn"]) )
{
if($_SESSION["wrongLogIn"]==true)
{
?>
<div class="alert alert-danger" role="alert">
wrong login
</div>
<?php
session_destroy();
}
}
/*if session is closed*/
if( isset($_SESSION["closedSession"]) )
{
if($_SESSION["closedSession"]==true)
{
?>
<div class="alert alert-info">
Closed Session
</div>
<?php
session_destroy();
}
}
?>
<?php include("views/view_login_register_forms.php"); ?>
<br><br>
<?php include("views/view_footer.php"); ?>
<?php
}/* end else*/
include('views/view_cookies-banner.php');
?>
</body>
</html>
view_login_register_forms.php
<div class="container">
<div class="card bg-light">
<article class="card-body mx-auto" style="max-width: 400px;">
<h4 class="card-title mt-3 text-center">MY REMINDER</h4>
<img src="assets/imagenes/bombilla.svg" class="img-responsive" alt="man_and_bulb">
<p class="divider-text">
<span class="bg-light">LOG IN </span>
</p>
<?php /* remember action path will be called from index*/ ?>
<form id="formLogIn" method="post" action="controls/loginUser.php">
<div class="form-group input-group">
<div class="input-group-prepend">
<span class="input-group-text"> <i class="fa fa-envelope"></i> </span>
</div>
<input name="email-Input-Name" class="form-control" placeholder="Email address" type="email" required>
</div> <!-- form-group// -->
<div class="form-group input-group">
<div class="input-group-prepend">
<span class="input-group-text"> <i class="fa fa-lock"></i> </span>
</div>
<input name="password-Input-Name" class="form-control" placeholder="Enter password" type="password" required>
</div> <!-- form-group// -->
<!--remember me checkbox-->
<div class="form-group input-group">
<input name="remember-Input-Name" id="id_remember_checkbox" type="checkbox" value="remember"> <label for="id_remember_checkbox" id="id_label_remember">Remember me</label>
</div> <!-- form-group// -->
<p>
<button type="submit" class="btn btn-primary" id="loginButton">Log in to your reminder</button>
</p>
</form>
<p class="divider-text">
<span class="bg-light">OR REGISTER</span>
</p>
<?php /* remember action path will be called from index*/ ?>
<form id="formRegister" method="post" action="controls/loginUser.php">
<div class="form-group input-group">
<div class="input-group-prepend">
<span class="input-group-text"> <i class="fa fa-user"></i> </span>
</div>
<input name="newUserName" class="form-control" placeholder="Name (required)" type="text" required>
</div> <!-- form-group// -->
<div class="form-group input-group">
<div class="input-group-prepend">
<span class="input-group-text"> <i class="fa fa-envelope"></i> </span>
</div>
<input name="email-Input-Name" id="id_email-Input-Name" class="form-control" placeholder="Email address (required)" type="email" required>
</div> <!-- form-group// -->
<label for="password-Input-Name">Password must be between 8-20 characters</label>
<div class="form-group input-group">
<div class="input-group-prepend">
<span class="input-group-text"> <i class="fa fa-lock"></i> </span>
</div>
<input name= "password-Input-Name" id="id_password-Input-Name" maxlength="20" class="form-control" placeholder="Password (required)" type="password" required>
</div> <!-- form-group// -->
<div class="form-group input-group">
<div class="input-group-prepend">
<span class="input-group-text"> <i class="fa fa-lock"></i> </span>
</div>
<input name="newUserPassRepeat" id="id_newUserPassRepeat" maxlength="20" class="form-control" placeholder="Repeat password (required)" type="password" required>
</div> <!-- form-group// -->
<input name="registerUserInputName" type="hidden" value="true">
<div class="form-group">
<button type="submit" class="btn btn-primary btn-block" id="registerButton"> Create Account </button>
</div> <!-- form-group// -->
</form>
</article>
</div> <!-- card.// -->
</div>
<!--container end.//-->
The app is here
https://myreminder.avanzartewebs.com/index.php
You can check how, for example, if you include en ampty email, it says things like "E mail already exists for another user" if there is an already created user with an empty email, and it should never be submitted when that happens.
The thing is, when I was developing it, I think required attribute worked... but it stopped working and I don´t know why or when.
I found part of the solution on this post
html5 required validator not working with input type=button
That's because the required validator is only called on submit
I had this code on another file that was causing the error:
$("#registerButton").click(function(e){
e.preventDefault();
//some code
}
What I did is to start working on the submit() event of the form, and not on the click() event of the button.
I found on this post, which helped me a lot.
Submit form after calling e.preventDefault()
I discovered it was a better idea to move the e.preventDefault() to the condition were validation is not right, so I could avoid the submit action only in case the condition is not true.
This is the resulting code which seems to be working now:
$(`#formRegister`).submit(function(e){
//e.preventDefault(); NOT HERE
let newPass=$(`#id_password-Input-Name`).val();
let repeatPass=$(`#id_newUserPassRepeat`).val();
let tamanioNewPass=newPass.length;
let tamanioRepeatPass=repeatPass.length;
/*if passwords are the same, and have minimun 8 characters, ok (16 characters maximum is controlled with html)*/
/*it is only neccesary to test if one of them is >= 8 , because if they are the same and one of them is >=8, the other is equal valid too*/
if((newPass===repeatPass) && (tamanioNewPass>=8) )
{
$(`#formRegister`).submit();
}
else
{
e.preventDefault(); //if pass is wrong, don´t submit!
alert(`could not be possible to do registration submit`);
}
});

knockout does not change the radio button view

I have a working panel with radio buttons a label and a textfield. Everything works good except if i click on radio buttons explicitly the radio button does not change the radio button view.
Here the plnkr link to it:
https://embed.plnkr.co/auD0sMEL88EsuaQqvt7E/
As #user3297291 mention that the checked and click binding get in confict.
Add this binding:
ko.bindingHandlers.stopBubble = {
init: function(element) {
ko.utils.registerEventHandler(element, "click", function(event) {
event.cancelBubble = true;
if (event.stopPropagation) {
event.stopPropagation();
}
});
}
};
You have to add in every radio element this binding like this:
<input data-bind="checked: discountValue, stopBubble: true" id="discountArbitrary" name="discount" type="radio" value="arbitrary" />
I created one jsfiddle that works as you expected.
https://jsfiddle.net/astrapi69/s3r60uLu/
I guess the click binding is conflicting with checked binding.
You can use computeds to calculate enabled/focused flags.
You can check modified code (I've omitted focused flags in favor of simplicity):
// Code goes here
var DiscountViewModel = function() {
var self = this;
self.arbitrary = ko.observable();
self.percent = ko.observable();
self.permanent = ko.observable();
self.discountValue = ko.observable('arbitrary');
self.enableArbitrary = ko.computed(() => self.discountValue() === 'arbitrary');
self.enablePercent = ko.computed(() => self.discountValue() === 'percent');
self.enablePermanent = ko.computed(() => self.discountValue() === 'permanent');
self.onArbitrary = onArbitrary;
self.onPercent = onPercent;
self.onPermanent = onPermanent;
function onArbitrary() {
self.discountValue('arbitrary');
}
function onPercent() {
self.discountValue('percent');
}
function onPermanent() {
self.discountValue('permanent');
}
};
var vm = new DiscountViewModel();
ko.applyBindings(vm);
/* Styles go here */
.header-line {
margin-bottom:20px;
margin-top:20px;
margin-left:20px;
}
<script data-require="jquery#2.1.3" data-semver="2.1.3" src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.3.3/js/tether.js"></script>
<link data-require="bootstrap#4.0.0-alpha.2" data-semver="4.0.0-alpha.2" rel="stylesheet" href="https://cdn.rawgit.com/twbs/bootstrap/v4-dev/dist/css/bootstrap.css" />
<script data-require="bootstrap#4.0.0-alpha.2" data-semver="4.0.0-alpha.2" src="https://cdn.rawgit.com/twbs/bootstrap/v4-dev/dist/js/bootstrap.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.0/knockout-debug.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js" type="text/javascript" defer="defer"></script>
<h1 class="header-line">
KO binding hasFocus over boolean values
</h1>
<div class="form-group row">
<div class="col-xs-1">
</div>
<div class="col-xs-1">
<input name="discount" type="radio" value="arbitrary" data-bind="checked: discountValue" />
</div>
<div class="col-xs-4">
<label for="arbitrary" data-bind="click: onArbitrary">Discount arbitrary</label>
</div>
<div class="col-xs-5">
<input type="text" class="form-control" id="arbitrary" placeholder="Enter arbitrary discount" data-bind="enable: enableArbitrary, value: arbitrary, hasFocus: enableArbitrary">
</div>
</div>
<div class="form-group row">
<div class="col-xs-1">
</div>
<div class="col-xs-1">
<input name="discount" type="radio" value="percent" data-bind="checked: discountValue" />
</div>
<div class="col-xs-4">
<label for="percent" data-bind="click: onPercent">Discount percent</label>
</div>
<div class="col-xs-5">
<input type="text" class="form-control" id="percent" placeholder="Enter percent of discount" data-bind="enable: enablePercent, value: percent, hasFocus: enablePercent">
</div>
</div>
<div class="form-group row">
<div class="col-xs-1">
</div>
<div class="col-xs-1">
<input name="discount" type="radio" value="permanent" data-bind="checked: discountValue" />
</div>
<div class="col-xs-4">
<label for="permanent" data-bind="click: onPermanent">Discount permanent</label>
</div>
<div class="col-xs-5">
<input type="text" class="form-control" id="permanent" placeholder="Enter permanent discount" data-bind="enable: enablePermanent, value: permanent, hasFocus: enablePermanent">
</div>
</div>
The problem is that by clicking the radio button, two things happen:
The checked binding does its thing
The event bubbles up to the parent element, and the click binding also does its thing.
You'll have to make sure clicking the input element stops the click binding from firing.
There's a great answer by R.P. Niemeyer here: https://stackoverflow.com/a/14321399/3297291