FormValidation.io with bootstrap select - bootstrap-select

I'm using Boost strap 4 and the bootstrap select jQuery plugin.
Im trying to integrate FormValidation.io with my forms. I have got everything working with normal input fields but cant figure out how to integrate it with the select field.
I would like it to be a required field and display the tick icon once a selection has been made.
my FormValidation.io code :
document.addEventListener('DOMContentLoaded', function(e) {
const mydropzone = document.getElementById('mydropzone');
const RoleIdField = jQuery(mydropzone.querySelector('[name="roleId"]'));
const fv = FormValidation.formValidation(mydropzone, {
fields: {
first_name: {
validators: {
notEmpty: {
message: 'First Name is required'
},
regexp: {
regexp: /^[a-zA-Z]+$/,
message: 'First Name can only consist of alphabetical characters'
}
}
},
last_name: {
validators: {
notEmpty: {
message: 'Last Name is required'
},
regexp: {
regexp: /^[a-zA-Z]+$/,
message: 'First Name can only consist of alphabetical characters'
}
}
},
roleId: {
validators: {
notEmpty: {
message: 'Please select a Role'
},
}
},
},
plugins: {
trigger: new FormValidation.plugins.Trigger(),
bootstrap: new FormValidation.plugins.Bootstrap(),
submitButton: new FormValidation.plugins.SubmitButton(),
icon: new FormValidation.plugins.Icon({
valid: 'fa fa-check',
invalid: 'fa fa-times',
validating: 'fa fa-refresh'
}),
}
}
);
});
$('#roleId').on('changed.bs.select', function (e, clickedIndex, isSelected, previousValue) {
// Revalidate the color field when an option is chosen
fv.revalidateField('roelId');
});
My form ID is 'mydropzone' and my select name and id are 'roleId'
Any help appreciated.

Thanks to the developers who answered my email, anyone else that needs to know how this is done:
add this to your css file :
.bootstrap-select i.fv-plugins-icon {
right: -38px !important;
then configure your js like this :
<script>
document.addEventListener('DOMContentLoaded', function(e) {
$('#gender').selectpicker();
const demoForm = document.getElementById('demoForm');
FormValidation.formValidation(demoForm, {
fields: {
gender: {
validators: {
notEmpty: {
message: 'The gender is required'
}
}
},
},
plugins: {
trigger: new FormValidation.plugins.Trigger(),
submitButton: new FormValidation.plugins.SubmitButton(),
bootstrap: new FormValidation.plugins.Bootstrap(),
icon: new FormValidation.plugins.Icon({
valid: 'fa fa-check',
invalid: 'fa fa-times',
validating: 'fa fa-refresh'
}),
}
});
});
</script>

Related

How do I return specific field of nested object array in angular having fields value?

I have an nested object array like this.
here is my array:
public collections: ICollections[] = [
{
collectionName: 'Brands',
collectionFields: [
{
columnTitle : 'brandTitle',
Type : dtEnum.string,
control: {
controlTitle: controlsEnum.input,
controlType: controlsEnum.input,
controlProperties:
{
placeholder: 'Enter brand title here ...',
type: 'text',
autocomplete: false,
}
},
columnWidth: 200
}
],
collectionFieldValidation: [{name: 'test'}],
hasPaginator: true,
stickyColumn: 0,
stickyHeader: true
},
{
columnTitle : 'brandURL',
Type : dtEnum.string,
control: {
controlTitle: controlsEnum.input,
controlType: controlsEnum.input,
controlProperties: {
placeHolder: 'Enter Brand URL',
type: 'text',
autocomplete: false,
}
},
columnWidth: 300
},
{
columnTitle : 'brandDescription',
Type : dtEnum.string,
control: {
controlTitle: controlsEnum.textarea,
controlType: controlsEnum.textarea,
controlProperties: {
placeHolder: 'Enter Brand Description',
type: 'text',
autocomplete: false,
}
},
columnWidth: 300
}
];
I want to reach to placeholder field. how do I find it by having only collectionName field with Brands value and columnTitle field with brandURL value ?
this question asked before just with collectionName field value but I find out that my filter should include more than one field.
first of all, find the collection that corresponds to "Brands" or any other thing:
let result = collections.find(p => p.collectionName === "Brands");
then get the placeholder field:
change your_index to 0 or your specific index
if (result) {
let placeholder = result.collectionFields[your_index].control.controlProperties.placeholder;
}
Here is my solution :
placeholder_finder(collectionSearchKey: string, fieldSearchKey: string): string {
let field: any;
let placeholder: string;
const obj = this.genInfo.collections.filter(
x => x.collectionName === collectionSearchKey
);
obj.forEach(data => {
field = data.collectionFields.filter(
x => x.columnTitle === fieldSearchKey
);
});
field.forEach(element => {
placeholder = element.control.controlProperties.placeHolder;
});
return placeholder;
}

Save current User into field within array in Mongoose

Here is a relevant part of my Schema, where I'll make reservations to a "space":
var spaceSchema = new mongoose.Schema({
spaceName: String,
scheduledDates: [{
scheduledDates: String,
author: {
id: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User'
},
username: String
}
}]
});
Author should be the current user that's logged in. Here is my route to update those fields:
router.put('/:space_id/schedule', function(req, res) {
Space.findByIdAndUpdate(req.params.space_id, {
'$push': { 'scheduledDates': req.body.space, 'author': req.user._id }
}, { "new": true, "upsert": true }, function(err, space) {
if (err) {
console.log(err);
} else {
console.log(req.body.space);
}
});
});
I can't access "author" correctly, because it's inside the array. What can I do to update this array, adding a new date and user to make the reservation?
Thank you
UPDATE
I tried to use "_id" instead of "id" in my property but got the same result. It seems like it's ignoring the "author" field, and only saving "scheduledDates"
So the schema was like this:
scheduledDates: [{
scheduledDates: String,
author: {
_id: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User'
},
username: String
}
}]
And then in my route, I changed what I was 'pushing':
'$push': { 'scheduledDates': req.body.space, 'author._id': req.user._id }
UPDATED 2
Changed the way I was getting the object to push:
'$push': {
'scheduledDates': {
'scheduledDates': req.body.space,
'author': { _id: req.user._id, username: req.user.username }
}
}
Now I'm getting the following error:
message: 'Cast to string failed for value "{ scheduledDates: \'04/11/2017\' }" at path "scheduledDates"',
name: 'CastError',
stringValue: '"{ scheduledDates: \'04/11/2017\' }"',
kind: 'string',
value: [Object],
path: 'scheduledDates',
reason: undefined } } }

Using Custom editors in grid column with Angular Kendo UI

I am trying to use custom editors for an editable kendo ui grid in my angular app.
For some reason( which I am not able to trace) the custom editor is not triggered.
I am expecting the following to be triggered but it does not work.
console.log("Editor Launched", options);
Here is the plunker for the same:
http://plnkr.co/edit/WioRbXA3LHVVRQD95nXA?p=preview
app.controller('MainCtrl', function($scope) {
$scope.model = {};
$scope.model.dataSource = new kendo.data.DataSource({
data: createRandomData(10),
schema: {
model: {
fields: {
City: { type: "string" },
Title: { type: "string" },
BirthDate: { type: "date" },
Age: { type: "number" }
}
}
},
pageSize: 16,
editable:true
});
$scope.addWWNumEditor= function (container, options) {
console.log("Editor Launched", options);
$('<input kendo-numeric-text-box k-min="10" k-max="20" style="width: 100%;" data-bind="value:' + options.field + '"/>')
.appendTo(container);
}
$scope.controlIsDisabled=function(model){
//console.log("model",(model.Age>=50));
var toReturn = (model.Age>50)?"columnDisabled" : "columnActive";
//console.log('to Return',toReturn);
return toReturn;
}
$scope.model.columns = [
{ field: 'City', title: 'City' },
{
field: 'Title',
title: 'Title',
template:'<span style="color:red;">EDITABLE</span><span ng-
class="controlIsDisabled(dataItem)">#=Title#</span>'
},
{
field: 'Age',
title: 'Age',
template:'<span ng-class="controlIsDisabled(dataItem)">#=Age#</span>'
,
editor:$scope.addWWNumEditor
}
];
});
Assuming your Plunkr mirrors your actual code, the primary problem I'm seeing is in your binding of k-columns on the grid element.
You currently have k-columns="{{model.columns}}", but the {{}} are unnecessary here. Changing to k-columns="model.columns" causes your editor function to execute as expected.

bootstrapvalidator for checkbox

I have a checkbox control which is dynamically filled. There are 3 checkboxes in the group. I am trying to check if at least one checkbox is selected, when user clicks on submit button. I have tried the below code, but I am not getting the error, and the page is getting saved. Below is the UI code
<input type="checkbox" id="{{method.id}}" value="{{method.value}}"
name="deliveryMethod[]" ng-model="method.selected"
ng-click="toggleSelection(method.value)"
ng-required="value.length==0"> {{method.value}}
In the js file, i tried as below:
jQuery("#createForm").bootstrapValidator({
framework: 'bootstrap',
excluded: [':disabled', ':hidden', ':not(:visible)'],
icon: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
TypeSelect: {
validators: {
callback: {
message: 'Please select the type',
callback: function (value, validator, $field) {
var options = validator.getFieldElements('testTypeSelect').val();
return (options != null && options.length >= 1);
}
}
}
},
testName: {
validators: {
notEmpty: {
message: 'name required.'
}
}
},
"deliveryMethod[]": {
validators: {
required: true,
minlength: 1,
maxlength: 3,
message: 'Delivery Type is Mandatory.'
}
},
}
How to make at least one checkbox is checked, if not show the message.
Thanks

why Angular schema form custom validation message is always Field does not validate?

I have the following:
vm.schema = {
type: 'object',
title: 'Account',
properties: {
username: {
type: 'string',
title: 'Username'
}
},
required: ['username']
}
vm.form = [
'username'
]
vm.submit = function() {
$scope.$broadcast 'schemaFormValidate'
$http.post('a link', vm.model).then(function(data) {
// somecode
}, function(response) {
$scope.$broadcast(
'schemaForm.error.' + response.data.errors[0].key,
response.data.errors[0].errorCode,
response.data.errors[0].message
);
});
}
so errors are detected from the server-side and the problem here is that I always get the error message as the following: Field does not validate
Add "validationMessage" : "some message"
to schema to override default message.

Resources