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

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.

Related

FormValidation.io with 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>

Node Feathers Sequelize API invalid column name

I am setting up an API to a SQL Server 2008 database using Node, Feathers and Sequelize. I have successfully created the models and services using feathers-sequelize-auto, and most of the routes seem to be working. The app runs but with an error message:
Unhandled Rejection at: Promise {"_bitField":18087936,"_fulfillmentHandler0":{}}
I'm getting an error for one of the routes (/project) relating to one of its foreign keys. Postman output for /project is:
{
"name": "GeneralError",
"message": "Invalid column name 'OrganisationID'.",
"code": 500,
"className": "general-error",
"data": {},
"errors": {}
}
All works fine in the database itself, and I can run queries on the related tables with no issues.
Relevant parts of the Project.model.js:
Field definitions
LeadAgency: {
type: DataTypes.INTEGER,
allowNull: true,
references: {
model: 'Organisation',
key: 'OrganisationID'
}
Relationships:
Project.associate = function(models) {
// Define associations here
// See http://docs.sequelizejs.com/en/latest/docs/associations/
Project.belongsTo(models.Team, { foreignKey: 'TeamID' });
Project.belongsTo(models.Subteam, { foreignKey: 'SubTeamID' });
Project.belongsTo(models.Staff, { foreignKey: 'StaffID' });
Project.belongsTo(models.Organisation, { foreignKey: 'OrganisationID' });
Project.belongsTo(models.Project, { foreignKey: 'ProjectID' });
};
And this is the Organisation.model.js code:
/* jshint indent: 2 */
// See http://docs.sequelizejs.com/en/latest/docs/models-definition/
// for more of what you can do here.
const Sequelize = require('sequelize');
const DataTypes = Sequelize.DataTypes;
module.exports = function(app) {
const sequelizeClient = app.get('sequelizeClient');
const Organisation = sequelizeClient.define(
'Organisation',
{
OrganisationID: {
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true
},
Name: {
type: DataTypes.STRING,
allowNull: false
},
Type: {
type: DataTypes.STRING,
allowNull: true
},
AddressID: {
type: DataTypes.INTEGER,
allowNull: true,
references: {
model: 'Address',
key: 'AddressID'
}
}
},
{
tableName: 'Organisation',
timestamps: false
},
{
hooks: {
beforeCount(options) {
options.raw = true;
}
}
}
);
// eslint-disable-next-line no-unused-vars
Organisation.associate = function(models) {
// Define associations here
// See http://docs.sequelizejs.com/en/latest/docs/associations/
Organisation.belongsTo(models.Address, { foreignKey: 'AddressID' });
};
return Organisation;
};
Noob here so could be missing something obvious. Help appreciated!
I got this error due to incorrect mappings in model.associate. In your Project model you have defined Project as associate also. This can be the reason.

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 } } }

Mongoose: 'Cast to embedded failed for value at path. Cannot use 'in' operator to search for '_id'

I'm having some trouble trying to save an array inside an array of objects.
I'm getting the following response from the server:
{ [CastError: Cast to embedded failed for value "\'maxbeds: 4\'" at path "saved_searches"]
message: 'Cast to embedded failed for value "\\\'maxbeds: 4\\\'" at path "saved_searches"',
name: 'CastError',
kind: 'embedded',
value: '\'maxbeds: 4\'',
path: 'saved_searches',
reason: [TypeError: Cannot use 'in' operator to search for '_id' in maxbeds: 4] }
Here's my Schema:
var mongoose = require('mongoose'),
rfr = require('rfr'),
passwordHelper = rfr('server/helpers/password.js'),
Schema = mongoose.Schema,
_ = require('lodash');
/*
*
* Creating UserSchema for MongoDB
*
*/
var UserSchema = new Schema({
email: {
type: String,
required: true,
unique: true
},
password: {
type: String,
required: true,
select: false
},
name: {
type: String,
required: true
},
passwordSalt: {
type: String,
required: true,
select: false
},
saved_houses: [{
mlsId: {
type: String
},
addressFull: {
type: String
},
bedrooms: {
type: Number
},
listPrice: {
type: Number
},
bathrooms: {
type: Number
},
sqft: {
type: Number
},
createdAt: {
type: Date,
default: Date.now
}
}],
saved_searches: [{
search_name: {
type: String
},
filters: {
type: [Schema.Types.Mixed]
},
createdAt: {
type: Date,
default: Date.now
}
}],
active: {
type: Boolean,
default: true
},
createdAt: {
type: Date,
default: Date.now
}
});
// compile User model
module.exports = mongoose.model('User', UserSchema);
The problem, I believe is the filters array that live inside an object inside the saved_searches array
Now, in my router I do the following:
var express = require('express'),
savedDataRouter = express.Router(),
mongoose = require('mongoose'),
rfr = require('rfr'),
s = rfr('server/routes/config/jwt_config.js'),
User = rfr('server/models/User.js'),
jwt = require('jsonwebtoken');
savedDataRouter.post('/searches', function (req, res) {
if (mongoose.Types.ObjectId.isValid(req.body.userId)) {
User.findByIdAndUpdate({
_id: req.body.userId
}, {
$push: {
saved_searches: {
search_name: req.body.search_name,
$each: req.body.filters
}
},
}, {
new: true
},
function (err, doc) {
if (err || !doc) {
console.log(err);
res.json({
status: 400,
message: "Unable to save search." + err
});
} else {
return res.json(doc);
}
});
} else {
return res.status(404).json({
message: "Unable to find user"
});
}
});
If I log the request body coming from the client I get the following:
//console.log(req.body)
{ search_name: 'Sarasota',
filters: [ 'minbaths: 1', 'maxbaths: 3', 'minbeds: 2', 'maxbeds: 4' ],
userId: '583359409a1e0167d1a3a2b3' }
I've tried all the things I've seen in Stack Overflow and other online resources with no luck. What am I doing wrong?
Edit
Added module dependencies to my UserSchema and SavedDataRouter
try this
User.findByIdAndUpdate({
_id: req.body.userId
}, {
$push: {
saved_searches: {
search_name: req.body.search_name,
filters: req.body.filters
}
},
}, {
new: true
},
function (err, doc) {
if (err || !doc) {
console.log(err);
res.json({
status: 400,
message: "Unable to save search." + err
});
} else {
return res.json(doc);
}
});

SOAP web services client with ExtJS, SOAP and JavaScript

I implemented SOAP web services with WildFly. Invocation of endpoint interface is successful. The below url returns the correct result.
http://localhost:8080/SOAPJaxbWeb/?operation=ICallMemberPort
But the ExtJS soap client does not work at all. These are my ExtJS soap client codes.
Ext.define('Member', {
extend: 'Ext.data.Model',
fields : [{
name : 'id',
type : 'string'
}, {
name : 'passwd',
type : 'string'
}, {
name : 'age',
type : 'int'
}, {
name : 'name',
type : 'string'
}]
});
Ext.onReady(function () {
var family = Ext.create('Ext.data.Store' , {
model : 'Member',
autoLoad : true,
proxy: {
type: 'soap',
url: 'SOAPJaxbWeb/',
api: {
read: 'ICallMemberPort'
},
soapAction: {
read: 'http://localhost:8080/SOAPJaxbWeb/?operation=ICallMemberPort'
},
operationParam: 'ICallMemberPort',
targetNamespace: 'http://www.aaa.com/',
reader: {
type: 'soap',
record: 'ns|return',
namespace: 'ns'
},
exception: function(proxy, response, operation){
Ext.MessageBox.show({
title: 'REMOTE EXCEPTION',
msg: operation.getError(),
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
});
}
},
listeners: {
load: function(family, operation, success) {
if(success) {
alert('response : ' + family.model.length)
} else {
alert('it failed')
}
}
}
});
var onButtonClick = function() {
Ext.Msg.alert(Ext.getCmp('myid').getValue())
family.load()
};
I am afraid above ExtJS soap configuration is wrong. When executed, nothing shows.
proxy: soap
Note: This functionality is only available with the purchase of Sencha Complete. For more information about using this class, please visit our Sencha Complete product page.
https://docs.sencha.com/extjs/6.0/6.0.1-classic/#!/api/Ext.data.soap.Proxy

Resources