Laravel-backpack; how to sort dropdown entries when using a field to enter a related id? - laravel-backpack

Classic example: each post has a user_id
in the creation operation, I added a field using the user relationship a field_name and backpack created for me a dropdown where to select a user name.
Fantastic, but, usernames are not in alphabetic order.
How can I sort entries in this situation?

Resolved (as documented)
I added options to the field definition
'options' => (function ($query) {
return $query->orderBy('username', 'ASC')->get();
}),

Related

TYPO3 displayCond: How can i specify additional optional conditions of the same field?

Basically: In the Backend i want to make specific fields only visible when the BE user chooses a specific value from a drop down menu of another field. I know i have to do this via displayCond in the TCAs, but i'm only able to define ONE condition or rather one value of the specific field to be the condition, like in this line:
'displayCond' => 'FIELD:checktype:=:4',
Checktype is a field that uses records from a foreign table in a select drop down menu. The specific condition is the Uid of my specified record. BUT: how can i add other Uids from the same field as optional conditions?
For instance, i experimented with this:
'displayCond' => 'FIELD:checktype:=:4||11||10',
Of course it doesn't work...
you might try:
'displayCond' => array (
'OR' => array (
'FIELD:checktype:=:4',
'FIELD:checktype:=:10',
'FIELD:checktype:=:11'
)
),

Pick list items in VSTS gets auto sorted

I'm trying to add some items (strings) to a pick list in VSTS. The items get auto sorted alphabetically (ascending order).
Below is the scenario:
I entered 'test' then 'abc' and then 'xyz', but it auto sorts and displays 'abc' then 'test' and then 'xyz'.
Is there any way to avoid this sorting and the items should be inserted in the order they were entered?
And I want to achieve this without writing an extension.
Yes, the values for the picklist (string) Type field can only ordered by alphabet so far.
But there has an user voice Custom Sort Order for TFS Fields (for VSTS, added in comment) about customzing sort order for fields, and you can vote and follow up.
if you are using VSTS, you cannot avoid the sorting or have your own sorting for a list field.

HTML::FormHandler with DBIC update extra database column before update_model

I'm using HTML::FormHandler (with DBIC) and I want to update a field on my model that depends on another field submitted on the form. HTML::FormHandler has a section on handling extra database fields, and it says when a row is created to do this in before update_model:
before 'update_model' => sub {
my $self = shift;
$self->item->my_other_column( manipulate_value($self->field('my_field') );
};
This works when I add a new item, but not when I edit it. When I edit the item my_field is updated but my_other_column is not. Does anyone know how I can accomplish this?
before 'update_model' works only when you add a new item.
From docs: If there is another database field that needs to be updated
when a row is created, add an attribute to the form, and then process it with before 'update_model'.
Try around 'update_model'.

Make records "Non-Editable" after certain approving in TCA TYPO3 backend forms.

I have an extension called calendar and it contains a record event. For an event to be displayed on the Front End it has be approved by the admin. But once the admin has approved/rejected it, the record should no longer be editable from the backend.
I want to do something like this :
TcaEvent.php
if ($currentRecord_Permission=='Accept' or $currentRecord_Permission=='Reject')
# Make the current record non-editable
else #make the current record editable
Will the $TCA array contain the details of the current record being edited? If so, I can use it to achieve the above mentioned.
Try to use 'editlock'. This is exactly what you need.
Field name, which – if set – will prevent all editing of the record
for non-admin users.The field should be configured as a checkbox type.
Non-admins could be allowed to edit the checkbox but if they set it,
they will effectively lock the record so they cannot edit it again –
and they need an Admin-user to remove the lock.Note that this flag is
cleared when a new copy or version of the record is created.This
feature is used on the pages table, where it also prevents editing of
records on that page (except other pages)! Also, no new records
(including pages) can be created on the page.
So all you have to do is to set this field to TRUE after admin will approve the record. Or even admin can set that field if the approve means he enter to edit the BE record anyway.
Read more here:
http://typo3.org/documentation/document-library/core-documentation/doc_core_tca/4.7.1/view/1/3/
Find 'editlock'.
Basically you have to define in your TCA waht field in table will be an editlock field like this:
$TCA['tx_address_domain_model_item'] = array(
'ctrl' => array(
'title' => 'Title'
'editlock' => 'editlock',
...
The $TCA is a configuration array and does not contain any data of any records. It just holds the configuration of all fields that TYPO3 uses. There is also not a field which prevents a record from beeing edited except an admin. To achive this, you can create a second page which holds approved records and make this page invisible for non admin users via the permission module. Just set the owner of the page to user admin and group admin.

Is there way to create & index N no. of 'fields' dynamically with Sphinx

I am using Sphinx (with Thinking Sphinx v2.0 for RoR plugin),
Lets say I have several indexes on User model, lets say on 'name', 'address' and its one-to-many associations like 'posts' , 'comments' etc.
This means searching by post content would return me the User who made the post, and using :fieldmask 'rank mode' of sphinx, I am able to determine that the user was searched due to matching of 'posts'. But user has 'many' posts. So how to determine which 'post' it matched.
Is there any way, while indexing I can specify the index dynamically.?
For e.g. If I can specify index 'post_1'='< post1content >' , 'post_5'='< post5content >' as different 'fields' for user1; similarly 'post_2', 'post_7' for user2, Thus after searching It would return me user2 matched with matching fields as post_7...
Sphinx can't have different fields for each record, I'm afraid, so what you're hoping to do isn't possible with that approach.
If you need to know which posts match a query, I'd recommend conducting the search on the Post model instead, and then you can refer to a post's user? You could sort by user_id before weight, or group by user_id (so only one post per user is returned)? You'd be able to bring in user data into the Post index definition (and if a post has one user, then that data is kept to single values, instead of many, per record).
Hope this gives you some clarity with your options.
If you know, you want to search for post_5 in one query, and for post_7 in another query, you may use json as {post_1:, post_2:}.
Problem is that you have to know number of post you are searching for.
Maybe look to: https://stackoverflow.com/a/24505347/1444576 -if it is similar to your example.