logo
down
shadow

Validate only parts of a form


Validate only parts of a form

By : user2954077
Date : November 21 2020, 07:31 AM
I wish this helpful for you You could look at computing the required attribute of each control that is to be validated and have that check which button is submitting the form. Tommy Vaaland has a function that does this:
code :
// Used to check which if a component triggered an update
function submittedBy( componentId ){
 try {
  var eventHandlerClientId = param.get( '$$xspsubmitid' );
  var eventHandlerId = @RightBack( eventHandlerClientId, ':' );
  var eventHandler = getComponent( eventHandlerId );  
  if( !eventHandler ){ return false; }

  var parentComponent = eventHandler.getParent();
  if( !parentComponent ){ return false; }

  return ( parentComponent.getId() === componentId );  
 } catch( e ){ /*Debug.logException( e );*/ }
}


Share : facebook icon twitter icon
Validate only specific parts of the form instead of whole form

Validate only specific parts of the form instead of whole form


By : Amr Selima
Date : March 29 2020, 07:55 AM
This might help you You seem to be using the "God Form" anti-pattern. Everything is thrown together in a single . This is a poor design/practice. Most sensible way would be to put the fields and buttons in separate forms so that only the related fields and buttons are in its own form so that the form submit doesn't unnecessarily submit/process/convert/validate irrelvant data in other forms.
See also: How to use in JSF page? Single form? Multiple forms? Nested forms?
code :
<p:inputText id="field1" ... required="true" />
<p:inputText id="field2" ... required="true" />
...
<p:inputText id="field3" ... required="true" />
<p:inputText id="field4" ... required="true" />
...
<p:commandButton id="c1" ... process="field1 field2" />
...
<p:commandButton id="c2" ... process="field3 field4" />
<p:inputText id="field1" ... required="#{not empty param[c1.clientId]}" />
<p:inputText id="field2" ... required="#{not empty param[c1.clientId]}" />
...
<p:inputText id="field3" ... required="#{not empty param[c2.clientId]}" />
<p:inputText id="field4" ... required="#{not empty param[c2.clientId]}" />
...
<p:commandButton id="c1" binding="#{c1}" ... />
...
<p:commandButton id="c2" binding="#{c2}" ... />
<c:set var="c1ButtonPressed" value="#{not empty param[c1.clientId]}" />
<c:set var="c2ButtonPressed" value="#{not empty param[c2.clientId]}" />
...
<p:inputText id="field1" ... required="#{c1ButtonPressed}" />
<p:inputText id="field2" ... required="#{c1ButtonPressed}" />
...
<p:inputText id="field3" ... required="#{c2ButtonPressed}" />
<p:inputText id="field4" ... required="#{c2ButtonPressed}" />
...
<p:commandButton id="c1" binding="#{c1}" ... />
...
<p:commandButton id="c2" binding="#{c2}" ... />
Validate parts of a Symfony form based on other parts of the form

Validate parts of a Symfony form based on other parts of the form


By : joajohn
Date : March 29 2020, 07:55 AM
will be helpful for those in need Make a "huge" validation method, then into validation itself, check for "selected options": if there are some, check for "sub-condition"
Something like
code :
use Symfony\Component\Validator\Constraints as Assert; 
/**
 *
 * @Assert\Callback(methods={"isValid"})
 */
class ObjectRelatedToYourForm
{
[...]
  public function isValid(ExecutionContext $context)
  {
    if ($this->optionOneSelected) {
      //perform controls and add violation in case of failure
    }
    if ($this->optionTwoSelected) {
      //perform controls and add violation in case of failure
    }
  }
}
jQuery Validation: Validate form in two parts

jQuery Validation: Validate form in two parts


By : Romain Dabadie
Date : March 29 2020, 07:55 AM
Does that help By design, you cannot call the .validate() method twice on the same form. The .validate() method is used for initialization and the second instance will always be ignored.
You have two options here:
code :
$(document).ready(function() {

    $("#form1").validate({ // initialize `form1`
        rules: {
            field1: "required"
        },
        messages: {
            field1: "Please specify your name"
        }
    });

    $('#btn').click(function() {
        $("#form1").valid();
    });

    $("#form2").validate({ // initialize `form2`
        rules: {
            field2: "required"
        },
        messages: {
            field2: "Please specify your name"
        }
    });

    $('#btnn').click(function() {
        $("#form2").valid();
    });
});
<form id="form1" name="form1"> 
    Field 1: <input name="field1" type="text" />
</form>

<form id="form2" name="form2">
    Field 2: <input name="field2" type="text" />
</form>

<div>
    <input id="btn" type="button" value="Validate"/>
    <input id="btnn" type="button" value="Validate"/>
</div>
ActiveModel Validate form has a negative value if true else validate form has a positive value

ActiveModel Validate form has a negative value if true else validate form has a positive value


By : Harshit Shukla
Date : March 29 2020, 07:55 AM
around this issue It turns out the above works if passed an actual boolean. I was passing a string of true or false. Once I converted the value of allow_negative to a true bool, it worked great.
I am having to use RegEx to validate several parts of a form

I am having to use RegEx to validate several parts of a form


By : KCLAV
Date : March 29 2020, 07:55 AM
like below fixes the issue Since it looks like this is an assignment, I've done my best to give hints instead of just giving you the answer.
Input elements have a pattern attribute. You can use this to more easily check the input against a regular expression without the need for any Javascript. There is a :valid CSS pseudo class. You can use this to style invalid elements instead of directly applying styles in an event listener. You can also use it to style the entire form (and thus any child elements) if any input is invalid, this would be my prefered solution for hiding the submit button.
shadow
Privacy Policy - Terms - Contact Us © ourworld-yourmove.org