javascript
  • jquery
  • html
  • jquery-validate
  • getorgchart
  • 2015-10-09 2 views 3 likes 
    3

    Я пытаюсь обновить элемент в GetOrgChart и что я делаю следующеезначение GetOrgChart не обновляется в Jquery валидатор

    Html

    <form id="one"> 
        <input type="text" name="aaa"> 
        <input type="text" name="bbb"> 
        <input type="submit" name='submitform' value="submit"> 
    </form> 
    <br> 
    <div id="people"></div> 
    

    JavaScript

    var oneForm = $("#one"); 
    $("#people").getOrgChart({ 
         clickEvent: function(sender, args) { 
          alert('args.id value outside validate '+args.id); 
    
          oneForm.show(); 
          oneForm.validate({ 
           // to add new area for team 
           rules: { 
            aaa: { 
             required: true, 
             minlength: 3 
            }, 
            bbb: { 
             required: true, 
             minlength: 3 
            } 
           }, 
           submitHandler: function (form) { 
            alert('args.id value inside validate '+args.id); 
            oneForm.hide(); 
            return false; 
           } 
          }) 
    
          //return false; //if you want to cancel the event 
         }, 
    
         primaryColumns: ["Name", "Type"], 
         linkType: "M", 
         editable: false, 
         zoomable: false, 
         movable: true, 
         gridView: true, 
    
         dataSource: [ 
          { id: 1, parentId: -1, Name: "Amber McKenzie", Title: "CEO", Address: "MyAddress"}, 
          { id: 2, parentId: 1, Name: "Ava Field", Title: "CTO", Phone: "+359 888 888 888"}, 
          { id: 3, parentId: 1, Name: "Evie Johnson", Title: "CFO", Car: "BMW"}] 
        }); 
    

    сейчас просто нажмите элемент диаграммы и отправьте форму, вы увидите, что

    значение args.id не меняется validate функции после первой нажмите

    JsFiddle

    ответ

    1

    вашей проблема, как представляется, объем переменных «аргументы».

    Это переменная «born» в анонимной функции, вызываемой по clickEvent, и она существует только внутри этого события.

    submitHandler - это обработчик, управляемый другой внутренней функцией; поэтому он выходит за рамки clickEvent.

    Таким образом, решение заключается в объявлении (вне обеих функций переменные со сферой страницы). Затем, при щелчке события, assegn это idargs. Таким образом, вы можете использовать его и в сообщении submit.

    Короче говоря (я заметил с "// ---" линией, которые я добавил):

    var oneForm = $("#one"); 
    var globalArgsId; //--- Declare "global" variable 
    $("#people").getOrgChart({ 
         clickEvent: function(sender, args) { 
          alert('args.id value outside validate '+args.id); 
          globalArgsId = args.id; //--- Write value to global variable 
    
          oneForm.show(); 
          oneForm.validate({ 
           // to add new area for team 
           rules: { 
            aaa: { 
             required: true, 
             minlength: 3 
            }, 
            bbb: { 
             required: true, 
             minlength: 3 
            } 
           }, 
           submitHandler: function (form) { 
            alert('args.id value inside validate '+args.id); 
            alert('args.id value inside validate '+globalArgsId); //--- Access to global variable 
            oneForm.hide(); 
            return false; 
           } 
          }) 
    
          //return false; //if you want to cancel the event 
         }, 
    
         primaryColumns: ["Name", "Type"], 
         linkType: "M", 
         editable: false, 
         zoomable: false, 
         movable: true, 
         gridView: true, 
    
         dataSource: [ 
          { id: 1, parentId: -1, Name: "Amber McKenzie", Title: "CEO", Address: "MyAddress"}, 
          { id: 2, parentId: 1, Name: "Ava Field", Title: "CTO", Phone: "+359 888 888 888"}, 
          { id: 3, parentId: 1, Name: "Evie Johnson", Title: "CFO", Car: "BMW"}] 
        }); 
    

    Надеется, что это помогает ... :)

    +0

    спасибо, вы сделали мой день –

    Смежные вопросы