FORMIO: I am trying to create custom field logic, and I want to select value of every field for eg.(data.firstName will select value of Firstname) - formio

let disableBool;
if(data.firstName === "disable"){
disableBool = true;
return disableBool;
}
result = disableBool;
This is an example of how I selected "Firstname" field and selected its value to perform some logic on it. Is there any way to select the value of every field so that for example if I type "disable" in any field then "disableBool = true".

Related

Add new field To collection in MongoDB but the value based on value in another field

How Can I add New Field To All Documents but Tha Value Based On value in Another Field?
Example :
{"_id":"1","city":"Amman"}
{"_id":"2","city":"Cairo"}
I Want to Add a new field to all documents (Capital) based on the city name if the city is Amman Capital will be true else false
I think what you trying to achieve is to add new field to each document based on the existing details in each of those document. Try this script with your collection details:
use YourDB;
db.YourCollection.find({}).forEach(function(doc){
if(doc.city =='whatever'){
doc.capital=true;
}else{
doc.capital=false;
}
db.YourCollection.save(doc);
});

How to update DB when field changed in mongoalchemy.(flask)?

I am using flask-mongoalchemy to do a demo, and here is a question confused me for a while.
At first I create a class User
class Student(db.Document):
'''student info'''
name = db.StringField()
grade = db.IntField(required=False, default=None)
Then, I use this DB and create some example, such as student1, student2...and so on。
Now, I change the default value of grade from None to 0
grade = db.IntField(required=False, default=0)
When I run query again, it raise error:
mongoalchemy.exceptions.BadValueException: Bad value for field of type "grade". Reason: "Value is not an instance of <class 'int'>
SO, how to auto-update this field change? What I did now is to modify the value of age in database manualy.
First, to get the queries working as before set allow_none option on the field to True.
grade = db.IntField(required=False, default=0, allow_none=True)
That should allow documents having no value for grades to not trigger errors when unwrapped as python objects.
Next, make a migration that sets the default value for documents where grade is None to 0.
from mongoalchemy.session import Session
with Session.connect('mongoalchemy') as s:
update = s.query(Student).filter(Student.grade == None).set(User.grade, 0)
update.execute()
Lastly, switch the field declaration back to disallow None values for the grade.

Redux Form, Dynamic name form implicate re registeredFields

I have a list and I try to create form for each item to submit them separately, each row is add dynamically. I use compose() to create each name of form dynamically, like this :
return {
formName: ownProps.form
}
And I pass the form name like this in my child component (item of list), list arrive from the reducer :
list.map((item, index) => (
<RowAuthorizations form={`${formName}[${index}]`} onSubmit={this.submitRowAuthorization} />
))
When i try to refresh my list fields without selected value from the reducer :
tenant.users.filter((x) => x.id !== action.payload.id)
Values of the field has been deleted but registeredFields reappear when my component re render the list without the deleted value.
When I add the field :
When I remove the field :
Finally, I solved my problem :
You need to add a nested object and add destroyOnUnmount: true (Defaults to true if you change it to false).
registeredField overrided each field when it was already mounted that's why my field has doesn't unregistered.
If you want to create a list and submit each row independently (each row is a form) you need to add a dynamic name to the form with mapStateToProps (dynamic name passed from the container) and recovered by an intermediate component like this :
return {
formName: ownProps.form
}
This formName need to be passed has a prop to each child (Form Row):
{ list.map((item, index) => {
return <RowAuthorizations form={`${formName}[${index}].${name}`} onSubmit={this.submitRowAuthorization} />
})
}
name is the sub object which contain registeredField, values,... so you have user[0].user.values unlike that user[0].values
If you use formReducer.plugin({}) and you want to manage form from your reducer for this case follow this steps.
Let me know, if i'm right.

APEX Trigger when a textfield gets updated

I am trying to create a trigger in APEX, when an custom textfield of an custom sObject gets updated with products (means, when new products get insert or existing one get deleted).
How can I compare in APEX the Trigger.Old values with the Trigger? New values of this field in order to start the Trigger.
It would look something like this:
Trigger NameOfTrigger on CustomSObject__c (after update){
/*there is already an existing list of products that get insert into the custom textfield (probably as Strings)
*/
List <String> textList = new List <String> ();
/*PseudoCode: if the textfield got updated/has changed, copy from every entry of this textfield (entry = product name as a string) and copy fieldX into another sObject
*/
if(CustomSObject.field(OldValues) != CustomSObject.field(NewValues)){
for (String product : textList){
//Trigger e.g. copy the values of a certain field of p and paste them in another sObject
}
Could somebody help me with the syntax?
You can utilize inbuilt Trigger.new and Trigger.old to get the latest and old values of any record. These lists can be used to achieve what you're looking for.
Sample example would be:
Trigger NameOfTrigger on CustomSObject__c (after update){
for(CustomSObject__c customObject : Trigger.new) {
// get old record
CustomSObject__c oldCustomObject = Trigger.oldMap.get(customObject.Id);
// compare old and new values of a particular field
if(customObject.fieldName != oldCustomObject.fieldName){
//Trigger e.g. copy the values of a certain field of p and paste them in another sObject
}
}
}
See documentation of Trigger.new & Trigger.old

TYPO3 - Adding values to a table using powermail

I made a form so that users can register their email address for a contest. Im using a powermail form and someone told me to use dbEntry to do this, but im not sure how to do it. This is my code so far:
plugin.tx_powermail_pi1{
dbEntry{
tt_address._enable = TEXT
tt_address._enable.value = 1
tt_address.email = TEXT
tt_address.email.value = ????
}
debug.output = all
}​
Ive been told to activate _enable to enable the data insertion. But now I dont know how to access the field value of the form. I probably should use the template id, which is ###UID71###, but I have no idea how.
According to the official documentation, you can do it this way:
plugin.tx_powermail.settings.setup {
dbEntry {
# enable or disable db entry for tt_address
tt_address._enable = TEXT
tt_address._enable.value = 1
# write only if field email is not yet filled with current value
# (update: update values of existing entry)
# (none: no entry if field is filled)
# (disable: always add values don't care about existing values)
tt_address._ifUnique.email = update
# fill table "tt_address" with field "pid" with the current pid (e.g. 12)
tt_address.pid = TEXT
tt_address.pid.data = TSFE:id
# fill table "tt_address" with field "tstamp" with the current time as timestamp (like 123456789)
tt_address.tstamp = TEXT
tt_address.tstamp.data = date:U
# fill table "tt_address" with field "name" with the value from powermail {firstname}
tt_address.name = TEXT
tt_address.name.field = firstname
...
}
}
I also found an (older) forum post (in German) with examples that use data from the user session:
# table "tt_address" with field "last_name" is the value from powermail (tt_content uid 88) field uid18 (###uid18###)
tt_address.last_name = TEXT
tt_address.last_name.data = TSFE:fe_user|sesData|powermail_88|uid18