how to validate in an each x-editable

0

I have the following table where I add a correlative to an item, Valid that the item is not blank and also that this is not repeated. Validate that this blank works well, but the one that does not repeat does not work, but I can not compare it.

$('#table').editable({
        container: 'body',
        selector: 'td.task',
        title: 'task',
        type: "POST",
        showbuttons: false,
         type: 'text',
        validate: function(value) {
            if ($.trim(value) == '') {
                return 'Empty!';
            }
                $("#table tbody > tr").each(function() {

                var celdas = $(this).find('td');
                var tasknum = $(celdas[1]).html();
                tasknum = $.trim(tasknum);

                if (tasknum==$.trim(value)) {
                  alert('id ya existe');
                  return 'Error Id ya existe';
                  // return [false,'Folio ya existe'];
                }
              });
        },  
        success: function(response) {
  
           $(this).parent().find(".Item").click();
        }
    });
    var ITEM = [];
    $.each({
        "Item1": "Item1",
        "Item2": "Item2",
        "Item3": "Item3",
        "Item4": "Item4"
    }, function(k, v) {
        ITEM.push({
            value: k,
            text: v
        });
    });
    
    $('#table').editable({
        container: 'body',
        selector: 'td.Item',
        title: 'Item',
        type: "POST",
        showbuttons: false,
        source: ITEM,
        validate: function(value) {
            if ($.trim(value) == '') {
                return 'Empty!';
            }
        }
    });
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet">
<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script> 
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/x-editable/1.5.0/bootstrap3-editable/js/bootstrap-editable.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/x-editable/1.5.0/bootstrap3-editable/css/bootstrap-editable.css" rel="stylesheet"/>
    <div class="col-sm-3">
     
                      </div>
<table id="table" class="table table-bordered">
  <thead>
    <tr>
      <th>Id</th>
      <th>Task</th>
      <th>Item</th>
      <th></th>
    </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td data-name="task" class="task" data-type="text">001</td>
  <td data-name="Item" class="Item" data-type="select">Item2</td>
  <td></td>
  </tr>
    <tr>
  <td>2</td>
  <td data-name="task"  class="task" data-type="text">002</td>
  <td data-name="Item"  class="Item" data-type="select">Item1</td>

  </tr>
   <tr>
  <td>3</td>
  <td data-name="task" class="task" data-type="text">003</td>
  <td data-name="Item" class="Item" data-type="select">Item3</td>
  <td></td>
  </tr>
  </tbody>
</table>
    
asked by MoteCL 10.12.2018 в 16:11
source

0 answers