admin-on-rest CreateButton doesn't pass record id of form - admin-on-rest

I am using ReferenceManyField to show the items in an order, the typical master/detail database pattern. I am able to edit existing detail records, but can't find a way to add new detail records. I tried the following, but doesn't receive {id} like does. I notice that admin-on-rest-demo allows editing of detail records (reviews of products), but does not allow adding of reviews. Is there a pattern or workaround to do this?
<SimpleForm>
<ReferenceManyField label="ITEMS" reference="orderitems" target="orderId">
<Datagrid>
// fields removed for clarity...
<CreateButton/> <===== does not pass {id} of form record
<EditButton/> <===== passes {id} of form record
</Datagrid>
</ReferenceManyField>
</SimpleForm>

I answered this question here:
Example: https://codesandbox.io/s/pp0o4x40p0
The relevant code parts are:
the CreateCommentButton component inside src/posts.js
the CommentCreate component inside src/comments.js (note how we set the defaultValue prop on SimpleForm)

Related

How do I add an "author" field in the strapi cms?

I can't figure out how to set up the links. I have created a collection. I need an creator to be automatically specified in that record when adding a record to the collection. How do I do that?
I've faced this problem...
I found the solution in the documentation:
need to add
"populateCreatorFields": true
in the file (strapi v3) /api/your-type-name/models/your-type-name.settings.json
in options object
like:
...
"options": {
"increments": true,
"timestamps": true,
"draftAndPublish": true,
"populateCreatorFields": true
},
...
More information can be found at strapi documentation
Strapi does not support it by default. As mentioned in this form you can achieve it by editing the strapi's controller. But I will not recommend you to edit the strapi controller at all. Please avoid it.
There is a simple and better solution to this. You can achieve this by creating one to one relationship. Create an author table/collection. Make one to one relationship with your other collection. You can make it a required option as well. So whenever someone creates an entry they have to select an author from your already created collection of authors.
And now you can get relation in your API and use it wherever you want to.
As stated in my comment, Strapi (tested on v3) comes with a created by field. To ascertain the claim, the following steps can be followed;
Create a new content type. Here I am setting only one field, called test
Add an entry for that content type. Notice the last update and by field on the right.
Save and open the entry. The last update and by fields have been automatically populated.

Dynamically add attributes to Laravel Blade components

I'm programatically building a form using Blade components and I can't find how to add attributes dynamically.
For example, I have an $attribute variable that contains ['data-id' => 123, 'step' => 0.01]. I want to integrate it to my form-number component so that the final result is equivalent to:
<x-form-number data-id="123" step="0.01" />.
Thank you.
<x-form-number :data-id="$attribute['data-id']" :step="$attribute['step']" />
from the doc
https://laravel.com/docs/8.x/blade#passing-data-to-components
The keys in the array are dynamic. I don’t know them in advance
Sure you know them in advance they are defined in your class. So you just have to popultae your array with all the keys (with defaut value accepted by your class)

Can we dynamically set the value of "list" attribute of <apex:relatedList> component?

I am trying to design a generalized detail page for an object.
In the controller class I find the list of all child relations of that object.
I then want to create for each child relations found and for accomplishing this I will have to dynamically set the value of list attribute within it.
For example :
<apex:relatedList subject={!ObjName} list="{!relatedListName}" />
But the problem here is that list attribute only accepts String literal, so can't implement it. Please suggest a way for this requirement to be accomplished.
Yes, you can dynamically set the value of the "list" attribute on a relatedlist tag, and you do so via Dynamic Visualforce. This question has since been asked and concisely answered here on the Salesforce Stack exchange for any future browsers:
https://salesforce.stackexchange.com/questions/7531/apexrelatedlist-list-dontexistinallorgs-c-only-solveable-with-dynamic
Here is the general solution:
In a custom controller, add a function to dynamically generate the RelatedList markup. I will assume from your wording that you have already accessed the full list of child relationships in your controller, so in order to spit out all the lists in one block, I would use something like this:
public Component.Apex.OutputPanel getDynamicList()
{
Component.Apex.OutputPanel outPanel = new Component.Apex.OutputPanel();
for(String id : childNames) {
Component.Apex.RelatedList relList = new Component.Apex.RelatedList();
relList.list = id;
outPanel.childComponents.add(relList);
}
return outPanel;
}
In the middle there, you can dynamically set any string to the "List" value, and by iterating through your list of strings, you are adding related list objects over and over again. (To simply add one list, remove the for loop, and make the "id" string value whatever specific relationship you wish to display).
Then on your visualforce page, you can render this block out using a dynamic visualforce tag:
<apex:dynamicComponent componentValue="{!DynamicList}" />
(as you may know, the formulaic value field will dig up the getter automatically)
Great success!
I would suggest trying apex:dataTable or apex:repeat to build your own list display. You will likely need a wrapper class to handle passing attributes and values from the sObject to the page.

{Magento} Split phone number entry

We are beginning to allow multi-national registrations and have the requirement to split the phone number entry in the OnePage checkout billing.
We want to add Country Code and split the rest into Area Code Number and Extension fields. Then we will need to concatenate them into one before storing them.
How would I accomplish that?
Could you not just use a hidden field and javascript? So add 2 fields, then use onchange="phonecat()" on each to trigger a function that concatenates then values and assigns them to the pre-existing telephone field, which you have changed to be type="hidden".
Something like the following in JQuery:
function phonecat() {
$(function(){
newphone = jQuery("#initialphone").val() + jQuery("#latterphone").val();
jQuery("#billing\\:telephone").val(newphone);
}(this.jQuery));
}
I've not tested this exact solution, but I've used something similar in the cart. Only the (now hidden) proper field will be passed and used.
File is .../persistent/checkout/onepage/billing/phtml in 1.6 (without persistent/ earlier). And you'll need to define the function somewhere too.

Is it possible to pass argument from visualforce apex tag?

I have a function searchWorkByName that takes "key" as an argument and use SQOL to retrieve the data.
In visualforce side, I have a link that calls searchWorkByName but would like to be able to pass argument such as character 'a'
example, (this throws an error)
<apex:commandLink value="search!" action="{!searchWorkByName('aaa')}" />
Is it possible to do so if not what is the alternatives?
apex class
public class SearchWorkTest {
public PageReference searchWorkByName(String key) {
//find record of work names starting from provided key character
workNames = [select name from work__c where work__c.name like 'key%'];
return Page.searchResult;
}
}
visualforce
<apex:page standardController="work__c" extenstions="SearchWorkTest">
<!-- Is it possible to pass argument like 'foo' ? -->
<apex:commandLink value="search!" action="{!searchWorkByName}" />
</apex:page>
You can pass in parameters from a page into a function like this:
<apex:commandLink value="search!" action="{!searchWorkByName}">
<apex:param name="key" value="val"/>
</apex:commandLink>
Obviously, the value of the parameter in this case is fixed. If you want something dynamic (i.e. user types something and that is passed to the function), I'm not 100% sure how you'd do that, but I think it might be possible. However, the solution already posted skins the cat for you, but I thought I'd follow up with an alternative in case it's any use.
No, you cannot pass arguments to actions like that.
1 option is to make this variable a normal form field that user can type text/select from dropdown/whatever - if you'll use same name for a variable in Apex (and make it publicly visible by setters/getters), this will work without problems. Check out my answer at How do I integrate Salesforce with Google Maps? to get started.
Second option - if this search must be somehow done programatically without user having to click anything, if the data for example comes from page itself (i.e. is read in <apex:repeat> tag)... you could make a small helper page & controller and call them as components. There is no problem with passing data to components. Check documentation for <apex:component> and <apex:componentBody>. But I think first answer os most useful for you.
Good luck!

Resources