如何更改羊驼的数组 - 表单生成器的名称

时间:2018-04-18 06:22:04

标签: jquery forms alpacajs

我遇到了一些问题。我正在为Alpaca表单做一个formBuilder。它的进展顺利,但是如何改变这个array的名字,里面有阵列或者我做错了。知道如何开始构建它吗?这是正确的方式吗?

jQuery(function($) {
    var data = {
        "schema": {
            "type": "object",
            "properties": []
        },
    };

    $('.modal-footer').on('click', '#qID', function(e) {
        var name = $("input#questionID").val();
        var question = $("textarea#question").val();
        console.log(data);

        var obj = {
            name: {
                "type": "string",
                "title": question
            }
        };
        data.schema.properties.push(obj);
        test = JSON.stringify(data);
        fulltest = test.replace("[", "");
        fulltest = fulltest.replace("]", "");
        console.log(fulltest);
        fulltest = JSON.parse(fulltest);
        $("#form").alpaca(fulltest);
        console.log(fulltest);
    });
});

问题是我需要获取名称的val并将其放在json的名称:{..是的地方。

我目前的结果是:

 {"schema":{"type":"object","properties":{"name THAT STRING NOT REPLACE WITH OBJECT NAME VALUE":{"type":"string","title":"qweqweqweq"}}}}

是否有人通过逻辑表单获得了良好的表单构建器?条件依赖? Alpaca支持它,但是我为它创建JSON时遇到了问题。

<div class="row">
  <div class="col-md-12 col-xs-12">
    <div class="card">
      <div class="card-header">
        <h5 class="card-title">Dodaj formularz</h5>
      </div>
      <div class="card-body">
        <div class="form-group">
          <label for="form_title">Tytuł formularza</label>
          <input type="text" name="form_title" id="form_title" class="form-control" />
        </div>
        <div class="row">
          <div class="col-md-9 col-xs-12" id="form">
          </div>
          <div class="col-md-3 col-xs-12">
            <button id="question" data-toggle="modal" data-target="#MyModal" class="btn btn-default">Pytanie otwarte</button>
            <button id="checkbox" class="btn btn-default">Pytanie wielokrotnego wyboru</button>
            <button id="list" class="btn btn-default">Rozwijana lista odpowiedzi</button>
            <button id="grid" class="btn btn-default">Pytanie wielokrotnego wyboru (grid)</button>
            <button id="number" class="btn btn-default">Odpowiedź w postaci liczby</button>
            <button id="data" class="btn btn-default">Odpowiedź w postaci daty</button>
          </div>
        </div>
        <div class="modal fade" id="MyModal" role="dialog">
          <div class="modal-dialog">

     <!-- Modal content-->
     <div class="modal-content">
       <div class="modal-header">
         <button type="button" class="close" data-dismiss="modal">&times;</button>
         <h4 class="modal-title">Settings</h4>
       </div>
       <div class="modal-body">
         <div class="form-group">
           <label for="questionID">Question ID</label>
           <input type="text" class="form-contsrol" id="questionID" placeholder="Your question ID">
         </div>
         <div class="form-group">
           <label for="question">Question</label>
           <textarea type="text" class="form-control" id="question"></textarea>
         </div>
         <div class="form-group">
           <label for="">Dependencies</label>
           <input type="text" id="dependencies" name="dependencies{this.value['choice']}" placeholder="Choice ID">
         </div>
       </div>
       <div class="modal-footer">
         <button type="button" class="btn btn-success" data-dismiss="modal" id="qID">Save</button>
         <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
       </div>
     </div>

   </div>
 </div>

0 个答案:

没有答案