Conversational Form with React. How to make multiple choice? - javascript

I am working with React(Next.js). I have a good example [https://codepen.io/space10/pen/JMXzGX][1] how to use multiple choise in simple HTML, but how to use it in React?
Here is my code
Here what I have in browser

Just keep adding objects into the array - as long as the name is the same, it seems to combine it.
Working Demo: https://stackblitz.com/edit/react-conversational-form-with-radio
this.formFields = [
{
'tag': 'input',
'type': 'radio',
'name': 'country',
'cf-questions': 'What is your country?',
'cf-label': 'ukraine',
'value': 'ukraine',
},
{
'tag': 'input',
'type': 'radio',
'name': 'country',
'cf-label': 'india',
'value': 'india',
},
{
'tag': 'input',
'type': 'radio',
'name': 'country',
'cf-label': 'sri lanka',
'value': 'sri lanka',
},
{
'tag': 'input',
'type': 'text',
'name': 'lastname',
'cf-questions': 'What is your lastname?'
}
];
Returns the form result something like this:
{ country: ["ukraine"], lastname: 'tasdasd' }

Related

JS: Do I override or add in fields when use _.extend() in express?

When I have an object and I put it as an extension of another object in which I put value for some of the extended fields - is it going to be rewritten or the value will be added to the old one?
For example if I have:
const PATCH_REQUEST_SCHEMA = {
'type': 'object',
'title': 'Some object',
'description': 'Some object Representation',
'properties': {
'name': {
'type': 'string',
'minLength': 1,
'maxLength': 256,
'title': 'Name'
}
};
const POST_REQUEST_SCHEMA = _.extend({}, PATCH_REQUEST_SCHEMA, {
'properties': {
'surname': {
'type': 'string',
'minLength': 1,
'maxLength': 256,
'title': 'Surname'
}
}
});
What would be the result for POST_REQUEST_SCHEMA.properties ?
Will it be:
{
'name': {
'type': 'string',
'minLength': 1,
'maxLength': 256,
'title': 'Name'
},
'surname': {
'type': 'string',
'minLength': 1,
'maxLength': 256,
'title': 'Surname'
}
}
or:
{
'surname': {
'type': 'string',
'minLength': 1,
'maxLength': 256,
'title': 'Surname'
}
}
I tested it manually - it rewrites/overrides the field "properties". So the answer is:
{
'surname': {
'type': 'string',
'minLength': 1,
'maxLength': 256,
'title': 'Surname'
}
}

onclick link fires google analytics gtag

what could be the problem why onclick does not fire the gtag. I tried all variantions of quotes.
<a href="https://www.site.de/analytics.php?page=1&del=TR-123" onclick="gtag('event', 'refund', {
'transaction_id': 'TR-123',
'value': 90.17,
'currency': 'USD',
'items': [{
'id': '402',
'name': 'Diamant 050-029-034 comfort',
'quantity': 1,
'price': '90.17'
}]
});">
Where do I have to use "" and where '
I think the issue is that this onclick is on a hyperlink.
<a href="https://www.site.de/analytics.php?page=1&del=TR-123" onclick="javascript:(function() {
gtag('event', 'refund', {
'transaction_id': 'TR-123',
'value': 90.17,
'currency': 'USD',
'items': [{
'id': '402',
'name': 'Diamant 050-029-034 comfort',
'quantity': 1,
'price': '90.17'
}]
});
return false;
); })()">

How to add children using orgChart?

I have create a tree diagram using orgChart.
code:
var datascource = {
'id': 1,
'name': 'Lao Lao',
'title': 'general manager',
'children': [
{ 'id':2,'name': 'Bo Miao', 'title': 'department manager' },
{ 'id':3,'name': 'Su Miao', 'title': 'department manager'},
{ 'id':4,'name': 'Hong Miao', 'title': 'department manager' },
{ 'id':5,'name': 'Chun Miao', 'title': 'department manager' }
]
};
$('#chart-container').orgchart({
'visibleLevel': 2,
'pan': true,
'data' : datascource,
'nodeContent': 'title',
'nodeId':'id',
'createNode': function($node, data) {
$node.on('click', function(event) {
$('#chart-container').orgchart('addChildren', $node,
{'id' : 7, 'name': 'Hong ', 'title': 'Test manager' }
);
});
}
});
Digram generation working fine.
I need to add child nodes on click by nodes using ajax.
Screen shot:
You can refer to this demo on codepen.io.
Generally, you can call the methods of orgchart plugin with the following form : )
var oc = $('#chart-container').orgchart{(...});
oc.method();

Angular.Copy does not allow me to create unique objects in a separate array

I'm building a configurator in AngularJS that uses the object $scope.data to allow users to edit the object via the front-end. The user can then save this object to a separate array in $scope.builds, allowing them to have multiple configurations. Here is the function that adds another configuration to $scope.builds.
$scope.addition = function(){
var newData = angular.copy($scope.data);
$scope.builds.push(newData);
}
Unfortunately, despite using the angular.copy function, all of the objects in the array of $scope.builds seem to be the same $scope.data object duplicated over and over.
EDIT:
Here is an abridged version of what $scope.data looks like:
$scope.data = [
{
'title': 'Select your configuration',
'required': true,
'options': [
{
'name': 'Option 1',
'select': true,
'filter': true
}, {
'name': 'Option 2',
'select': false,
'filter': true
}, {
'name': 'Option 3',
'select': false,
'filter': true
}
]
}, {
'title': 'Select your configuration',
'required': true,
'options': [
{
'name': 'Option 1',
'select': true,
'filter': true
}, {
'name': 'Option 2',
'select': false,
'filter': true
}, {
'name': 'Option 3',
'select': false,
'filter': true
}
]
}
];

I want to access inputed Value in JSON array using javascript

i created array 'PROPERTIES' which accept value like username, password,sid etc.And i want to access this entered value using javascript.
'PROPERTIES': {'gatewayurl':
{'Name':
{
'en': 'Input gatewayurl'
},
'Description': {
'en': 'Input gatewayurl for sms gateway'
},
'Type': 'string',
'Required': 'Y',
'Multiple': 'N',
'Default': '',
},
'username':
{'Name':
{
'en': 'Input username'
},
'Description': {
'en': 'Input username'
},
'Type': 'string',
'Required': 'Y',
'Multiple': 'N',
'Default': '{=Document:NAME}',
},
'password':
{'Name':
{
'en': 'Input string'
},
'Description': {
'en': 'Input password'
},
'Type': 'string',
'Required': 'Y',
'Multiple': 'N',
'Default': '{=Document:NAME}',
},
'sid':
{'Name':
{
'en': 'Input string'
},
'Description': {
'en': 'Input sid'
},
'Type': 'string',
'Required': 'Y',
'Multiple': 'N',
'Default': '{=Document:NAME}',
},
'mobileno':
{'Name':
{
'en': 'Input mobileno'
},
'Description': {
'en': 'Input mobileno'
},
'Type': 'number',
'Required': 'Y',
'Multiple': 'N',
'Default': null,
},
'message':
{'Name':
{
'en': 'Input message'
},
'Description': {
'en': 'Input message'
},
'Type': 'string',
'Required': 'Y',
'Multiple': 'N',
'Default': null,
}
},
i Used php code But i want Access value using only Javascript Please Some one Help me
$url =$_REQUEST["properties"]["gatewayurl"];
$user = $_REQUEST["properties"]["username"];
$password = $_REQUEST["properties"]["password"];
$sid = $_REQUEST["properties"]["sid"];
$number= $_REQUEST["properties"]["mobileno"];
$message= $_REQUEST["properties"]["message"];
If "PROPERTIES" is an array as you were saying you should initialize it as an array.
var PROPERTIES = [ {'gatewayurl' ........... }]
Then you can get values by
var url = PROPERTIES[0].gatewayurl;
var user = PROPERTIES[0].username;
var password = PROPERTIES[0].password;
var sid = PROPERTIES[0].sid;
etc..
If its a JSON Array as shown in your example,
var REQUEST = {
'PROPERTIES': {'gatewayurl' ... }
}
Then you can get values by
var url = REQUEST["properties"]["gatewayurl"];
var user = REQUEST["properties"]["username"];
var password = REQUEST["properties"]["password"];
var sid = REQUEST["properties"]["sid"];

Categories

Resources