将事件处理程序添加到文本框撇号ecms中



我是撇号世界的新手,我正在尝试将事件添加到文本框中,例如,当他们键入国家名称时,我想检查数据库,看看这个国家是否已经存在,我用我创建的一个小部件来为每个位置添加国家和特定办公室,所以我希望在用户键入信息时有更多的控制权,比如让电话字段只接受数字而不接受字母等等。我希望我说清楚了哈哈非常感谢的帮助

我是ApostropheCMS团队的一员。

ApostropheCMS目前不支持对其标准字符串和文本区域字段进行自定义前端和后端验证。但是,它确实支持自定义模式字段类型。这是一条有充分文档记录的路径,可以创建具有所需行为的自己的字段类型。因此,我建议采用这种方法。我链接到这里的文档提供了一个完整的示例。

我确实创建了一个新字段,我称之为isUnique:

self.addFieldType({
name: 'isUnique',
converters: {
string: function(req, data, name, object, field, callback) {

object[name] = self.apos.launder.string(data[name]);
/* Checking the object _edit. Mode */
switch(object._edit){
case true:

/* Checking if the Name of the Country Name has Changed */
if( object[field.options[0].fieldToCompareMode].toLowerCase().trim() !== data[field.options[0].fieldToCheck].toLowerCase().trim() ){

return callback('required');
//       /* Checking if the Content Already exists.  */
//       (async () => {
//         await self.apos.docs.db.findOne({
//           title: data[field.options[0].fieldToCheck] 
//         })
//         .then((response, reject) => {
//           console.log('Data ' + response);
//           if(response === null){
//             console.log('achou o erro')
//             /* The Content Already exists, throwing an error*/

//             return setImmediate(callback(null));
//           }
//         })
//         .catch(callback)
//       })();

};

//     console.log('Edit Mode........');
//   break;
//   case undefined:
//     console.log('Undefined .............');
//     break;
}
return setImmediate(callback);
},
form: 'string'
},
exporters: {
string: function(req, object, field, name, output, callback) {
// no formatting, set the field
output[name] = object[name];
return setImmediate(callback);
}
},
index: function(value, field, texts) {
var silent = (field.silent === undefined) ? true : field.silent;
texts.push({ weight: field.weight || 15, text: value, silent: silent });
},
isEmpty: function(field, value) {
return !value.length;
},
addFilter: function(field, cursor) {
cursor.addFilter(field.name, {
finalize: function() {
if (self.cursorFilterInterested(cursor, field.name)) {
var criteria = {};
criteria[field.name] = new RegExp(self.apos.utils.regExpQuote(cursor.get(field.name)), 'i');
cursor.and(criteria);
}
},
safeFor: 'manage',
launder: function(s) {
return self.apos.launder.string(s);
},
choices: function(callback) {
return self.sortedDistinct(field.name, cursor, callback);
},
});
},
// validate: function(field, options, warn, fail, schema) {
//   if (!field.choices) {
//     // optional for booleans
//     return;
//   }
//   if (!Array.isArray(field.choices)) {
//     warn('If present, field.choices must be an array');
//     return;
//   }
//   _.each(field.choices, function(choice) {
//     _.each(choice.showFields || [], function(name) {
//       if (!_.find(schema, { name: name })) {
//         warn('showFields includes ' + name + ', a field that does not exist in the schema');
//       }
//     });
//   });
// }
});

当我试图调用async时,我无法创建回调,例如This字段Already exists。

最新更新