Lightswitch Search screen - choosing what you can search by - search

I have a search screen which shows results from a 'projects' entity. One of the fields is a link to a 'Clients' entity, which has a client name.
I can use the search box above the data to search by project name, date, etc but I cannot search by client name. i guess because it is actually a reference to a seperate entity.
How can i make it so that I can search for projects, using the search box, by client name?
To try to explain clearer here is the database layout.
Project
------
ProjName
ProjType
ProjComment
Client --------------- Client
-----
Name
Address
I can search by the project fields, but not the client name.

Create a custom query for Project entity and add optional parameters for all the Project and Client properties that you wish to search for. Wire up the custom query filter.
For full control do not wire up the custom query filter, instead filter in code behind, the PreProcess event.

if your using the HTML Client it can be done as follows on a browse screen associated with in your case the Project Table. if you look at the left navigation bar, click on edit query and within here, you can see 3 options, Filter, Sort and Parameters.
Filter should say Client.Name based on your table structure, the second should be changed to "contains", the 3rd should be set as parameter and finally the 4th box is where you create the new parameter you are going to use as a search box...
you can rename the Parameter at the bottom and I always find its best when on this, to set it as optional in the bottom right property box. (This means all the data will be displayed rather than nothing until searched)
Now if you were to go back to your main screen page, drag this parameter from the left onto the main screen page and set it as a text box. Using this and pressing enter after you have typed something will display the results that match what you have typed so far.
a little more to the above, if you were to click "Edit PostRender Code" and add the below then after 3 characters are entered, the table list your searching through will be updated automatically after each finger stroke...
$searchBox = $("input", $(element));
setTimeout(function () {
$searchBox.focus();
}, 1);
onInputAsYouType(element, 1, function (text) {
contentItem.screen.[CREATED PARAM NAME] = text; //SearchText here is the data item in the screen designer linked to the query parameter
});
function onInputAsYouType(element, numberOfRequiredChars, done) {
var inputbox = $("input", $(element));
inputbox.on("input", function (e) {
var text = $(this).val();
if (text.length >= numberOfRequiredChars)
done(text);
});
};
};

Related

How to display dynamic default value in field of Strapi collection page?

I want to display some read only URL in STRAPI collection page.
let's say I am at
/admin/plugins/content-manager/collectionType/application::my-public-form.my-public-form/1
now I have one field that need to display URL like this
https://myurl/1
is there is any way to get current url i.e. /admin/plugins/content-manager/collectionType/application::my-public-form.my-public-form/1
and in field I display https://myurl/1
This is going to be a lengthy answer, but let me try to simplify as much as possible.
Explanation:
To achieve this you need to simply create a field in the collection type and mark it as non-editable in the admin interface. This will make it a read-only property. Next, we need to override the afterFindOne from the lifecycle hooks of the model so that when it fetches the entry from the db, we can pre-populate the url for that particular entry, so that it's displayed in the read-only field in the UI.
Implementation:
Let's assume we are creating a collection-type called Student, which some basic field like first_name, last_name, dob and student_url. We are going to make the student_url field read-only in the following way:
Create the collection type Student as show in the screenshot.
Visit the newly created collection-type in the content-manager, click on Create new entry button, and then click on Configure view in the right hand panel.
Click on the small pencil icon which is besides the student_url field to open a popup, and then set the Editable property to False and click Finish.
At this point you're almost done, the only thing left to do is set the lifecycle hook to populate the student_url field when it's fetched from the database so that it's displayed correctly in our UI.
Create a lifecycles.js file in your model folder.
// src/api/student/content-types/student/lifecycles.js
module.exports = {
afterFindOne(event) {
const { result } = event;
// You can easily change this line to `/admin/plugins/content-manager/collectionType/application::my-public-form.my-public-form/${result.id}` in your project.
if (result) result.student_url = `https://example.com/${result.id}`;
},
};
And that's it. Now create an entry in the admin UI with the rest of editable fields and see entry being populated automatically with the student_url. Cheers!

Acumatica Mobile Modify the Location fields to be able to scan a barcode

We are currently using the Acumatica Mobile to process Bin Transfers. We are also looking at the Scandit app to be able to scan the from and to bin location labels in the warehouse. So far with testing We can scan the locations, but only in the search window. We would like to be able to scan/enter the locations on the main screen without going to the search window. It seems the selector forces you to go to the search window. Is there a way around this in Acumatica Mobile.
This is a fairly old question with a relatively new solution. I am using 2020R1 where we now can leverage the built-in scanning capability in the Mobile App.
Your field must be defined in the ASPX as a textedit. Then simply add the field to the mobile app screen (if not already there) and decorate it with special = BarCodeScan as shown in the example below.
add screen ZZ301000 {
add container "ScanContainer" {
add field "MyBarcode"
{
special = BarCodeScan
}
add containerAction "Insert" {
icon = "system://Plus"
behavior = Create
}
add recordAction "Save" {
behavior = Save
}
add recordAction "Cancel" {
behavior = Cancel
}
add recordAction "Insert" {
behavior = Create
}
}
}
The result will be similar to the image below:
By clicking on the barcode icon, the built-in barcode reader will open to utilize the camera to scan the barcode.
You can try to set ForceType to "String" for the Location field to replace selector with a text edit. This will allow to type values directly on the form, but you will loose all selector functionality, like searching for records. Another option is to set the PickerType property to Searchable. For more information about the Field tag attributes, please refer to Acumatica Product Documentation

Magento Filer the data by attribute before algolia search

Am trying to provide the Algolia search option with filter by attribute value. For example from the attached pic, need to filter the data by city attribute and then Algolia shows results results accordingly to selected attribute
Click Here for image
First you need to add the select box with searchable attribute before search input. I assume you use Algolia's Magento extension.
If it's the case you need to put your select box into either autocomplete.phtml file (if you are using default search box selector) or to your theme's template (if you modified search box selector in Algolia settings in Magento administration).
Then if you want to do it on instant search result page you can use searchFunction to restrict searchable attributes:
var search = instantsearch({
[...],
searchFunction: function(helper) {
var searchableAttribute = $('selectbox-selector').val(); // Using jQuery just for example
helper.setQueryParameter('restrictSearchableAttributes', searchableAttribute);
helper.search();
}
}
Initialization of instantsearch you can find in instantsearch.phtml template.
If you want to update results in autocomplete menu, you will have to set the restrictSearchableAttributes parameter to autocomplete data source. The data sources are defined in commonjs.phtml file. More information of autocomplete data sources you can find in autocomplete.js documentation.
Example of updating product's data source:
options.facets = ['categories.level0'];
options.numericFilters = 'visibility_search=1';
options.restrictSearchableAttributes = $('selectbox-selector').val();

Grid filtering based on drop down value

I have a html drop down and an extjs grid.
I want to implement searching functionality using the drop down...
The ext grid has to show the records based on the selected value of the drop down. and the grid has paging also...
I implemented this like
In drop down change event i'm loading store with the search parameters
searchGrid.store.load({params:{start:0, limit:10, year: searchVal}});
This works fine for the first page..
Grid shows records according search params....
But when i click the next page button in paging bar.... search params are missing....
how to handel this....
Is there any other way to implement this kind of search...
Help thanks.
Welcome to SO
Add a beforeload handler to the store that initializes the params everytime the store needs to be loaded (whether by user selecting a dropdown value or click the next button)
Your code would be something along the lines of -
Ext.onReady(function() {
//...some initialization code
Ext.getCmp('your-grid-id').getStore().on('beforeload', function(store, options){
options.params.year=Ext.getCmp('your-combo-id').getValue();
});
//....some more initialization code
});
If your combo does not always a value (for example, if it does not have a default value when it is loaded, you will have to modify options.params.year=Ext.getCmp('your-combo-id').getValue(); accordingly.

Drupal: re-selecting taxonomy terms in advanced search

I'm sure I'm not the first one to try to address this, but Google isn't doing me any good.
If you use the Advanced Search in Drupal to filter on taxonomy terms, the search form comes back with the term IDs in the keyword textbox like so:
search phrase category:32,33
The chosen values are NOT selected again in the taxonomy select box.
Instead of showing them in the keyword textbox, I would like them to be selected in the taxonomy select box - the way that any user would expect a form like this to act. I have been looking for a module that will add this functionality, to no avail. I have tried implementing hook_form_alter() to set the #default_value on that form element based on the previous form submission (available in the $form_state arg), but a) this seems kludgy and b) it seems that this function is called once to validate the form and again to re-display it, and the submitted value isn't available the second time (which is when it's needed).
Any suggestions?
It took much longer than it should have, but I finally figured out how to do this. I may release a module on the Drupal site later on, but in case anyone else has this same problem, this was the solution I came to.
Create a module and use hook_form_alter() to modify the form. I already had a module I was using to customize the advanced search, so I put it in there. I won't get into the detail of building your own module - you can find a simple tutorial for that, and you only need to define this one function.
/**
* Implementation of hook_form_alter().
* Remove 'category:x,y,z' from the keyword textbox and select them in the taxonomy terms list
*/
function modulename_form_alter(&$form, $form_state, $form_id) {
// Advanced node search form
if ($form_id == 'search_form' && $form['module']['#value'] == 'node' && user_access('use advanced search')) {
// Remove category:x,y,z from the keyword box
$searchPhrase = $form['basic']['inline']['keys']['#default_value'];
if(!empty($searchPhrase) && strpos($searchPhrase, 'category:') !== false) {
$searchWords = explode(' ', $form['basic']['inline']['keys']['#default_value']);
foreach($searchWords as $index=>$word) {
if(strpos($word, 'category:') === 0) {
// Use the value to set the default on the taxonomy search
$word = substr($word, strlen('category:'));
$form['advanced']['category']['#default_value'] = explode(',', $word);
// Remove it from the keyword textbox
unset($searchWords[$index]);
}
}
// Re-set the default value for the text box without the category: part
$form['basic']['inline']['keys']['#default_value'] = implode(' ', $searchWords);
}
}
}
Thanks for sharing this. After several drupal installations I am facing this problem now, too. However, this time I had to use some search extensions like search_config and search_files to meet the clients requirements. Furthermore, I'm using better_select which turns select lists into lists of checkboxes (easier to select mulitple values on long lists). Thus, the checkboxes always returned some value (either the id if selected or 0 (zero) if not selected) and I ended up with something like "search phrase category:0,0,0,0,...,0".
Your solution above indeed removes the "category:0,0,0,0,0,0,...,0" string from keyword search field and checks all taxonomy terms correctly. The same can be done for content types, you'll just have to replace "category:" by "type:" throughout the whole script.
Paul

Resources