I use jsf form with a few inputs. Some inputs are required. I check on an empty space through required="true". But i need to check before submit form if user just typed a few gaps space-key from keyboard, cause then the value is stored in the database, but I don't need it. I thought it may be implement using jQuery method trim(), but I'm a new to jQuery and I have no idea how to implement it.
<h:form prependId="false">
<div class="row">
<div class="col-lg-3 form-group">
<label>First Name<span class="text-danger"> *</span></label>
<h:inputText value="#{userController.user.firstName}"
styleClass="form-control" id="firstName"
required="true" requiredMessage="#{bundle.common_error_empty_value}"/>
<h:message for="firstName" styleClass="validationMsg"></h:message>
</div>
<div class="col-lg-5 form-group">
<label>Last Name:<span class="text-danger"> *</span></label>
<h:inputText value="#{userController.user.lastName}"
styleClass="form-control" id="lastName"
required="true" requiredMessage="#{bundle.common_error_empty_value}"/>
<h:message for="lastName" styleClass="validationMsg"></h:message>
</div>
</div>
//etc...
</h:form>
I tried something like this. Maybe someone have an idea how I can check fields on white spaces.
<script type="text/javascript">
function trimInputs() {
$('form input').each(function () {
$.trim(value);
});
}
</script>