Я должен предотвратить ввод списка разделителей по умолчанию Coldfusion ',' во входной массив формы.Я новичок в использовании javascript для целей проверки и никогда не пытался отключить значения, которые кто-то печатает. Как я могу зацепить запятую и заменить ее на тильду?
Javascript, который я пробовал такfar:
$(document).ready(function(event){
var regExComma = /,/;
$("[name='name[]']").live("keypress",function(event){
// i know i could check the numerical value, i feel this requirement can get more added to it and I would like to just change the regEx accordingly.
if(regExComma.test(String.fromCharCode(event.which)){
//it was a ',' switch it to '~'
event.which = 126;
}
});
// added to show that the 'name' input form array is the only input that cares about the ','
var regExDig = /[\d]/
$("[name=min[]],[name=max[]]").live(keypress, function(event){
if(!regExDig .test(String.fromCharCode(event.which)){
event.preventDefault();
$("#cfocFormMessages").trigger("updateMessages", {"url":"components.cfc/CFOC.cfc", "data":{"more":"stuff"}});
}
});
});
cfml / html вовлечен:
<form action="components/CatagoryService.cfc?method=saveVersion">
<input id="version" name="version" type="text">
<!--- .. more inputs ..--->
<table id="table">
<thead><tr><th>name col</th>
<th>min col</th>
<th>max col</th>
<th>edit</th>
</tr></thead>
<tfoot></tfoot>
<cfoutput query="variables.query">
<tr><td><input name="name[]" type="text" value="#variables.query.name#"></td>
<td><input name="min[]" type="text" value="#variables.query.min#"></td>
<td><input name="max[]" type="text" value="#variables.query.max#"></td>
<td><input name="id[]" type="hidden" value="#variables.query.id#">
<a href="#" class="editLink">edit</a></td>
</tr>
</cfoutput>
<tr><td></td><td></td><td><a href="#" class="addLink">add</a></td></td></tr>
</table>
<input type="Submit"/>
</form>
если я изменю CatagoryService.cfc? method = saveVersion на <cfreturn arguments>
в строке JSON, типичный ответ Coldfusion выглядиткак:
{VERSION:"",name:"name1,name2",min:"1,3", max:"2,4",id:"1,2"}