portfolio/src/main/webapp/comments.js
// creates input element with the given params
creates input element with the given params
creates input element with the given params
function createFormInput(type, name, placeholder, value = null, hidden = false) {
  const input = document.createElement('input');
  input.type = type;
  if (input.type === 'text') {
    input.required = true;
    input.addEventListener('input', function(event) {
      if (input.value.trim().length === 0) {
        input.setCustomValidity('Field has only spaces, please add some text instead');
      } else {
        input.setCustomValidity('');
      }
    });
  }
  input.name = name;
  input.placeholder = placeholder;
  if (value !== null) {
    input.value = value;
  }
  input.hidden = hidden;
  return input;
}
function createFormInput ( type , name , placeholder , value = null , hidden = false ) { const input = document . createElement ( 'input' ) ; input . type = type ; if ( input . type === 'text' ) { input . required = true ; input . addEventListener ( 'input' , function ( event ) { if ( input . value . trim ( ) . length === 0 ) { input . setCustomValidity ( 'Field has only spaces, please add some text instead' ) ; } else { input . setCustomValidity ( '' ) ; } } ) ; } input . name = name ; input . placeholder = placeholder ; if ( value !== null ) { input . value = value ; } input . hidden = hidden ; return input ; }
creates input element with the given params
creates input element with the given params
// if type of the input is 'text', then it must have value before submitted // if value is spaces or empty, set an error // otherwise field is considered valid