2017-10-19 62 views
2

如何在igGrid更新中的igTextEditor上使用正則表達式?如何在IgGrid細胞中獲得正則表達(Infragistics)?

我試圖使用驗證選項,但它沒有奏效。

$("#schedulerTable").igGrid({ 
      columns: $scope.schedulerColumns, 
      width: "87%", 
      height: "300px", 
      fixedHeaders: true, 
      autoGenerateColumns: false, 
      autofitLastColumn: true, 
      autoCommit: true, 
      renderCheckboxes: true, 
      responseDataKey: "results", 
      dataSource: $scope.schedulerData, 
      updateUrl: "", 
      primaryKey: 'Id', 
      features: [ 
      { 
       name: "Updating", 
       generatePrimaryKeyValue: function (evt, ui) { 
        nextPrimarykey -= 1; 
        ui.value = nextPrimarykey; 
       }, 
       enableAddRow: true, 
       enableDeleteRow: true, 
       editMode: "row", 
       columnSettings: [ 
        { 
         columnKey: "Id", 
         editorType: "numeric", 
         editorOptions: { 
          readOnly: true 
         } 
        }, { 
         columnKey: "Time", 
         editorType: "text", 

         editorOptions: { 
         }, 
         validatorOptions: { 
          regExp: /^[a-zA-Z]{1}[a-zA-Z0-9_\.\-]*\@\w{2,10}\.\w{1,10}$/, 
          onblur: true, 
          onchange: true 
         }, 

         required: true, 
         validation: true, 
         defaultValue: "00:00" 
        }, 
        { 
         columnKey: "Mo" 

        }, 
        { 
         columnKey: "Tu" 

        }, 
        { 
         columnKey: "We" 

        }, 
        { 
         columnKey: "Th" 

        }, 
        { 
         columnKey: "Fi" 

        }] 
      }] 
     }); 

我想實現時間列中的時間選擇器,但不存在,所以我嘗試通過正則表達式獲取textEditor中的時間。 網格將加載名爲Time,Mo- Friday的列。 如果您點擊添加網格,您可以點擊輸入字段並填寫您的時間。在點擊完成之前應該驗證時間並顯示錯誤消息。

,看看錶什麼樣子:https://codepen.io/ablablabla/pen/PJLbJz

+0

任何html代碼來理解這個單獨的JS代碼。 – 2017-10-19 15:51:10

+0

@headmax如果您使用infragistics工具,您可以創建一個網格,只需在div的id上調用igGrid。所以如果你要測試這個或者檢查它,你所要做的就是callig $('#whatever')。igGrid({});獲得完整的工作網格。 – Amsel

+0

例如這個https://codepen.io/headmax/pen/QqYZgq – 2017-10-20 07:39:52

回答

3

缺乏驗證的是,因爲validatorOptions屬於editorOptions(那些得到傳承給你選擇作爲供應商任何編輯器)。 validation: true只會得到一些默認值,除了必需的值外,對於文本字段來說真的不會有太大的效果。

然後是正則表達式選項(這是在上面的代碼片段的電子郵件,據我可以告訴),因爲15.2 :)一直pattern那麼,到底該時間欄,你可以嘗試:

//... 
    editorOptions: { 
    validatorOptions: { 
     pattern: /^\d{1,2}\:\d{2}$/, 
     onblur: true, 
     onchange: true 
    }, 
    }, 
//.. 

這裏有一個更新的codepen:https://codepen.io/anon/pen/YrgYxj

編輯:或者,如果你要設置的錯誤消息:

//... 
    editorOptions: { 
    validatorOptions: { 
     pattern: { 
     expression: /^\d{1,2}\:\d{2}$/, 
     errorMessage: "Time should match a pattern like 00:00" 
     }, 
     onblur: true, 
     onchange: true 
    }, 
    }, 
//.. 

根據你的目標,你不需經過d也使用Mask EditorDate Editor作爲提供者。此外,強制性文件鏈接:https://www.igniteui.com/help/iggrid-updating

P.S.綁定到一個空數組以避免第一行沒有值且更重要的是主鍵的錯誤。

+0

如果通知不符合該模式,我該如何更改通知?感謝您的好解決方案。 – Amsel

+0

@Amsel您可以設置全局'errorMessage'或爲模式檢查提供一個。我已經爲後者添加了一個片段。 –