Repository
https://github.com/knacksteem/knacksteem.org
Pull Request
https://github.com/knacksteem/knacksteem.org/pull/63
This PR add a new tagging feature for the knacksteem editor, which uses tag validation on the first tag to be apart of the knacksteem category. Also with this PR the following issues were fixed.
https://github.com/knacksteem/knacksteem.org/issues/55
https://github.com/knacksteem/knacksteem.org/issues/59
https://github.com/knacksteem/knacksteem.org/issues/57
A simple validation for the tags below
/**
* @method checkTags -- method to validate tags for any error
*
* @param {Array} rule -- all rules to validate
*
* @param {Array} value -- all values from tag selection
*
* @param {Function} callback -- callback funtion
*/
checkTags = (rule, value, callback) => {
if (!value || value.length < 1 || value.length > 4) {
callback('You have to add 1 to 4 tags');
};
if (value){
const {isComment} = this.props;
const {categories} = this.props.articles;
if (!isComment && categories.map(elem => elem.key).indexOf(value[0]) === -1) {
callback('first tag must be any of the following; graphics, art, vlog, knack, techtrends ');
}
}
value
.map(tag => ({ tag, valid: /^[a-z0-9]+(-[a-z0-9]+)*$/.test(tag) }))
.filter(tag => !tag.valid)
.map(tag => callback(`Tag ${tag.tag} is invalid`));
callback();
};
If there are no values, or the values in the array are less than for, we initiate a callback. that informs the user.Next we also check if the tag is a valid tag with the regex matching.
What's next?
Integration of Voting Slider and fixing some bugs on the repo.