Lowercase and merge words together in JavaScript value - javascript

I can't seem to figure out what's going on on a form field input that gets stored inside a SharePoint column data collection.
I have a form field set when someone inputs a name that it automatically gets populated in a SharePoint list:
Here is what I currently have:
Output:
Profile Username: fhWestern Union
This is what I want to be able to achieve on all the inputs:
Output:
Profile Username: fhwesternunion
Here is the currently JavaScript code bit that I have grabbing the data:
ACI_Username: "fh" + $("#ACI_client-name-input").val(), // Username
I have tried adding this below and it did not work with my code.
.toLowerCase().val()

Replace
$("#ACI_client-name-input").val()
With
$("#ACI_client-name-input").val().replace(/\s+/g,'').toLowerCase()

this is it
ACI_Username = "fh" + $("#ACI_client-name-input").val().replace(" ", "").toLowerCase();

Related

How to check for duplicate text entries in form with multiple pages?

I tried to create a form with two pages, and I was wondering if is there any way to check for duplicate text entries on different pages.
In my case, I would like to check if the first field from the first page has the same value as the first field from second page and send an alert before submitting the form.
Here is the code : https://codepen.io/ceres999/pen/ExVGdVq
For example, if I type in " hello " in both first fields from both pages send the alert " Duplicate values! ".
Considering that I already have an onsubmit function, what would be the way to check the two entries?
You can save the entry from form 1 and check it with the entry from form 2
text1.addEventListener('change', function(e) {
value1 = e.target.value;
});
text3.addEventListener('change', function(e) {
value3 = e.target.value;
});
if(value1!==value3){
console.log('values not same')
}

meteor.js & mongoDB - query with multiple fields

CONTEXT
I am trying to create a search functionality allowing users to fill in multiple fields, submit, and see a list of matching items from one collection. I do this using a form on the front end, which updates session variables on back-end, which are then passed as query to a mongodb collection.
HOW IT SHOULD WORK
If a user submits a venue size, then venues of that size are shown. If only a location is typed in, then venues within that location are shown. If both a size and a location are submitted, then venues that match both criteria are shown.
HOW IT ACTUALLY WORKS
If nothing is filled in, pressing search yields all items in the collection. Submitting both location and size yields venues that match both criteria. However, filling in only one field and leaving the other empty yields nothing in results. I'm wondering why this might be - it's almost as if the query is searching for a field that literally contains ''... but then why don't I see this behavior when leaving both fields empty? Help much appreciated!
CODE SNIPPET
//Search Form Helper
Template.managevenues.helpers({
venue: function () {
var venueNameVar = Session.get('venueNameVar');
var venueLocationVar = Session.get('venueLocationVar');
if(venueNameVar || venueLocationVar){
console.log(venueNameVar);
console.log(venueLocationVar);
return Venues.find({
venueName: venueNameVar,
'venueAddress.neighbourhood': venueLocationVar
});
} else {
return Venues.find({});
}
});
The answer lies in your query
Venues.find({
venueName: venueNameVar,
'venueAddress.neighbourhood': venueLocationVar
});
If you don't have one of your vars set it will look like this...
{
venueName: undefined,
'venueAddress.neighbourhood':'someVal'
}
So it would match any venue that doesn't have a name and is in some neighborhood.
A better approach would be to only set query criteria if there's a value to search...
var query = {};
if(Session.get('venueNameVar')) {
query.venueName = Session.get('venueNameVar');
}
if(Session.get('venueLocationVar') {
query.venueAddress = {
neighbourhood : Session.get('venueLocationVar');
}
}
return Venues.find(query);
I think this will work a bit better for you!

What is the proper way to assign an array item's value based on a checkbox status?

I was hoping this would work:
var title = document.getElementById('cat_title');
var active = document.getElementById('cat_active');
var category = {
title: title.value,
active: $(active).prop("checked");
}
When the form is submitted, and if the checkbox is checked, it inserts "true" into the active field. When it's not checked, it sends nothing but I'd like it to actually send "false".
Example of saved document if form is submitted WITHOUT checkbox checked:
{
_id: "lklajdlfjkasdf",
title: "Some Title"
}
Example of saved document if form is submitted WITH checkbox checked:
{
_id: ";klajsdfadsf"
title: "Some Title",
active: true <-- saved as boolean, good.
}
I'd like to keep the logic within the array. I understand another method to handle this... well there are several. I can perform some if/else and push to the array, but I feel I'm missing something simple with this array.
Thank you!
-------- Edit ---------
Details requested:
I'm inserting the record as a document in MongoDB. When the checkbox isn't checked, it inserts nothing into the active key/value pair. To answer various comments throughout, I need this as a boolean value, not a string. I'm trying some of the suggestions now and will update. Thank you all very much.... I've also updated my question above in more detail.
Even if that code carried the false value up to the database insertion, inserting a false value into the database will only make it a null field, which is the equivalent of setting it to nothing.
So the two options you have are to:
1) Check for a null field when retrieving the rows from the database
OR
2) Use the string value of "false" in the database and check for that instead

AngularJS: ng-repeat to assign different values to buttons; how to extract the value to js when pressed?

I am using angular to build a waitinglist-system, where you first join a waitinglist, and then can be moved to the memberlist. I use ng-repeat to fill inn the table with the rows of waiting people, and I assign a button to each row, which can be pressed to move that particular person to the memberlist.
First problem:
I am not sure if i assign the value to the button in the correct way. It is supposed to be the email of the person.
<input type="submit" ng-click="makeMember()" ng-model="member" value="Member" id="{{person.email}}">
Second problem:
I want to use this users email in order to make a sql query to send to the database to move the person to the memberlist (email is primary key).
I am trying to use $scope.member to reference the ng-model, but that only gives me an undefined value.
The makeMember function is just to see if it works (which it doesnt).
$scope.makeMember = function() {
alert("Person email: " + $scope.member);
};
Any help is highly appreciated!
Pass member in like this: ng-click=makeMember(member).
$scope.makeMember = function(member) {
alert("Person email: " + member);
};
Live demo here (click).
The issue you are having is that $scope refers to the controller's scope, not the child scope created by ng-repeat. The only way $scope.member would work is if you had defined it in the controller.

parsing json encoded array in javascript

I am returning a json encoded object to javascript back from PHP and i wish to parse it before displaying it: However there are a few limitations.
1.I cannot refer to each individual line such as user.Relation, because if the field is empty(and it can be) I will not return it to javascript.
2. I don't know the exact fields that will be returned.
3. It is simply too large to template out even if I did know the individual fields.
when I append it to my div $('#return').append(data);
I get
{"Name":"Mike","Day Phone":"xxx-xxx-xxx","Evening
Phone":"xxx-xxx-xxx","Relation":"Parent","Email":"test#test.com","Cell
Phone/Pager":"xxx-xxx-xxx"}
which is technically correct, but I want something like :
Name: "Mike"
Cell Phone/Pager: "xxx-xxx-xxx"
Day Phone: "xxx-xxx-xxx"
Email: "test#test.com"
Evening Phone: "xxx-xxx-xxx"
Relation: "parent"
...
what would be my optimal(fastest) and cleanest way to parse this data out?
var s = '';
for (var sAttr in json) {
s += '<b>'+sAttr+':</b> ' + json[sAttr]+'<br/>';
}
$('#return').append(s);
Is what I would do.

Categories