Formulaire de reponse jquery

Bonjour,mon soucis c'est créer un formulaire qui se crée automatiquement,lorsqu'on clique sur créer ,après des recherches j'ai trouvé ceci
https://jqueryui.com/dialog/#modal-form
mais lorsque je copie le script qu'on m'a donné pour recopier il ne marche pas
si quelqu'un pouvais m'aider.

1 réponse

  1. Salut,

    Sans voir ton code il va être difficile de t'indiquer où est l'erreur.
    Peux tu nous montrer ce que tu as essayé ?

    Bonne journée,
    0
    1. voici mon script jquery
      function button() {
      var dialog, form,
      reponses = jQuery( "#reponses" ),
      justification = jQuery( "#justification" ),
      allFields = add( reponses ).add( justification ),
      tips = $( ".validateTips" );

      function updateTips( t ) {
      tips
      .text( t )
      .addClass( "ui-state-highlight" );
      setTimeout(function() {
      tips.removeClass( "ui-state-highlight", 1500 );
      }, 500 );
      }

      function checkLength( o, n, min, max ) {
      if ( o.val().length > max || o.val().length < min ) {
      o.addClass( "ui-state-error" );
      updateTips( "Length of " + n + " must be between " +
      min + " and " + max + "." );
      return false;
      } else {
      return true;
      }
      }

      function checkRegexp( o, regexp, n ) {
      if ( !( regexp.test( o.val() ) ) ) {
      o.addClass( "ui-state-error" );
      updateTips( n );
      return false;
      } else {
      return true;
      }
      }

      function addUser() {
      var valid = true;
      allFields.removeClass( "ui-state-error" );

      valid = valid && checkLength( reponses, "reponses", 3, 16 );
      valid = valid && checkLength( justification, "justification", 6, 80 );

      // valid = valid && checkRegexp( reponses, /^[a-z]([0-9a-z_\s])+$/i, "reponses may consist of a-z, 0-9, underscores, spaces and must begin with a letter." );
      // valid = valid && checkRegexp( justification, justificationRegex, "eg. ***@***" );
      //valid = valid && checkRegexp( password, /^([0-9a-zA-Z])+$/, "Password field only allow : a-z 0-9" );

      if ( valid ) {
      $( "#users tbody" ).append( "<tr>" +
      "<td>" + reponses.val() + "</td>" +
      "<td>" + justification.val() + "</td>" +
      "</tr>" );
      dialog.dialog( "close" );
      }
      return valid;
      }

      dialog = $( "#dialog-form" ).dialog({
      autoOpen: false,
      height: 300,
      width: 350,
      modal: true,
      buttons: {
      "Create an account": addUser,
      Cancel: function() {
      dialog.dialog( "close" );
      }
      },
      close: function() {
      form[ 0 ].reset();
      allFields.removeClass( "ui-state-error" );
      }
      });

      form = dialog.find( "form" ).on( "submit", function( event ) {
      event.preventDefault();
      addUser();
      });

      $( "#create-user" ).button().on( "click", function() {
      dialog.dialog( "open" );
      });
      }

      et le code de mon formulaire
      <body>

      <div id="dialog-form" title="Create new user">
      <p class="validateTips">All form fields are required.</p>

      <form>
      <fieldset>
      <label for="reponses">reponses</label>
      <input type="text" reponses="reponses" id="reponses" value="Jane Smith" class="text ui-widget-content ui-corner-all">
      <label for="justification">justification</label>
      <input type="text" reponses="justification" id="justification" value="***@***" class="text ui-widget-content ui-corner-all">
      <!-- Allow form submission with keyboard without duplicating the dialog button -->
      <input type="submit" tabindex="-1" style="position:absolute; top:-1000px">
      </fieldset>
      </form>
      </div>

      <div id="users-contain" class="ui-widget">
      <h1>Existing Users:</h1>
      <table id="users" class="ui-widget ui-widget-content">
      <thead>
      <tr class="ui-widget-header ">
      <th>reponses</th>
      <th>justification</th>

      </tr>
      </thead>
      <tbody>
      <tr>
      <td>oui</td>
      <td>non</td>
      <td>detail</td>
      </tr>
      </tbody>
      </table>
      </div>
      <button id="create-user">Create new user</button>

      </body>
      0
    2. mon souhait ai que ca marche comme dans le code d'origine
      0