Customized model values / output ngx-formly - angular-formly

I am trying to use ngx-formly to render forms. (using the FormlyFormConfig Object)
The form is rendering properly and i am getting model values as json object .
But is it possible that instead of setting the form fields values to model values i can set the values to the FormlyFormConfig "defaultValue" field ?
if not , is it possible to set additional attributes to the model.
This is because my form is tied to a field ids which are coming from backend and wated to set the values to same same formfieldconfig so that the backend knows which field the values belong to .
Here is the sample

As I correctly understood your question, you can add a default value to the field.
For example:
test.component.ts:
public form = new FormGroup({});
public model = {};
public options: FormlyFormOptions = {};
public fields: FormlyFieldConfig[];
this.fields = [{
key: 'name',
type: 'input',
defaultValue: name, // you can add default value
templateOptions: {
label: 'Name',
placeholder: 'Name',
},
}];
test.component.html:
<formly-form
[form]="form"
[fields]="fields"
[model]="model"
[options]="options"
></formly-form>

Related

Is it possible to search for keys within an object within a field within a document in mongoDB?

I have a form on a page, I want a user to enter something in the form click submit, then make a request to MongoDB using the input of that form and render parts of that request onto a page, using nodejs, mongoose, and ejs
The schema of the collection has a field that always contains an object and I would like to search for a document in the collection that has a key that matches the input of the form.
The schema of the collection is
const ArrivalTimesSchema = new mongoose.Schema({
postcodeArrivalTimes: {
type: Object,
required: true,
},
workerId: {
type: String,
required: false
},
company: {
type: String,
required: true
},
})
And an example of postcodeArrivalTimes is
postcodeArrivalTimes = {AL95AT:"07:06", DL56EP:"13:06",AL14PL:"19:15"}
So in this case if someone input AL95AT into the input form I would want this document returned, how would I do that?
Not all documents would contain the key AL95AT but there could be multiple and I would like the last.
For this I think I can use .sort({ $natural: -1 }).limit(1) within a find() but I am not sure how to search for the keys within the object within the field.
Thank you for any help!!
let input = "input" //inputKeyValue
let query = {};
query[input] = { $exists: true };
db.collection.find(query).sort({ $natural: -1 }).limit(1)

custom fields for address are not being saved?

I added some custom fields for address for in a twig template which extends from
#Storefront/storefront/component/address/address-form.html.twig
when i submit the form from the /checkout/register page, the custom fields are not saved.
In the Shopware\Core\Checkout\Customer\SalesChannel\RegisterRoute.php file, when data mapping is done for address, only the fields below are mapped:
private function mapAddressData(DataBag $addressData): array
{
$mappedData = $addressData->only(
'firstName',
'lastName',
'salutationId',
'street',
'zipcode',
'city',
'company',
'department',
'countryStateId',
'countryId',
'additionalAddressLine1',
'additionalAddressLine2',
'phoneNumber'
);
if (isset($mappedData['countryStateId']) && $mappedData['countryStateId'] === '') {
$mappedData['countryStateId'] = null;
}
return $mappedData;
}
How can i save custom fields for an address when developing an app? is it possible ?
There's this repository (not mine) with an example on how to add additional inputs to the storefront and how to map them to the payload when persisting the address. Basically you subscribe to the corresponding CustomerEvents, take the user inputs and enrich the payload.

How to customize link properties when creating ArangoSearchView in ArangoJS

I try to create an ArangoSearchView in arangojs, but I don't know how to set up view properties.
Here is my code:
const link = {
includeAllFields: true,
fields: { val: { analyzers: ["text_en"] } },
storeValues: "val"
};
const view = _db.view(`${_viewName}`);
await view.create({ links: {mergeDB : link } });
However, I got this result:
As the error says the issue it's with the storeValue field
According the docs the value should be either none (default) or id
storeValues (optional; type: string; default: "none")
This property controls how the view should keep track of the attribute values. Valid values are:
none: Do not store value meta data in the View.
id: Store information about value presence to allow use of the EXISTS() function.
Not to be confused with storedValues, which stores attribute values in the View index.
Note that there is other parameter called storedValues but it's a top level field (same level as links)

How to perform SubmitFields onto a custom record in SuiteScript 2.0?

To perform SubmitFields onto standard Netsuite Records (i.e. Purchase Orders) it is something like this:
var poId = context.key;
var id = record.submitFields({
type: record.Type.PURCHASE_ORDER,
id: poId,
values: {
custbody_someField: someValue
},
options: {
enableSourcing: false,
ignoreMandatoryFields : true
}
});
What is the type field for Custom Records? I tried the ID of the Custom Record, but it doesn't work:
e.g.
type: record.Type.customrecord_my_record_id
I don't know what the 'official' answer is. The fake enum types don't have any custom record references that I was able to find. Setting the type to the string that is the id of the custom record works for me. (No record.Type. prefix though)
... type: "customrecord_my_record_id", ...
That is true that the references are only for standard record types. You can alternatively get all enums into a variable and log it using
var recordTypesEnums = Object.keys(record.Type);
//you may log recordTypesEnums array

Force pair of attributes to be unique

I have a model which contains relationships between a user and his contacts.
Here is the current code for this model :
module.exports = {
connection: 'mysqlServer',
attributes: {
user: {
model: 'user',
required: true
},
contact: {
model: 'user',
required: true
}
}
};
What I would like is to make the combo user and contact uniques. That means that there may be several identical users and several identical contacts but only one user with a specific contact (ie: we can have user=1, contact=1 and user=1, contact=2, but we can't have user=1, contact=1 and user=1, contact=1).
The unique validation property is not enough to create the validation I want.
Do you have an idea how I should proceed? With custom validation rules maybe?

Resources