Skip to content

Instantly share code, notes, and snippets.

Created May 21, 2011 21:53
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Fancy MODX / ExtJS combo-box that searches while typing and adds new entries if they don't exist.
// Call the form with the unique xtype
items: [{
xtype: 'campermgmt-newcamper-form-brandscombo',
fieldLabel: 'Merknaam',
name: 'brand',
id: 'brand',
allowBlank: false,
vtype: 'alphanum'
// Declare the actual xtype
CamperMgmt.formGeneral.BrandsCombo = function(config) {
config = config || {};
url: CamperMgmt.config.connectorUrl,
baseParams: {
action: 'mgr/index/getbrands'
fields: ['id','name'],
// Editabel makes you able of typing in the combobox
editable: true,
// typeAhead sends posts for every character you type in (starting at minChars) to search for existing matches.
typeAhead: true,
minChars: 1,
// disabling forceSelection allows you to use a non-existent value
forceSelection: false
// This file is posted to when the entire form gets submitted, and does the magic of adding the field if it doesn't exist.
// Find the object based on the "brand" posted value
$brandObj = $modx->getObject('cmBrand',array('name' => $scriptProperties['brand']));
// If it is not empty (ie it exists), simply add it to $c, which is the camper record
if (!empty($brandObj)) {
// If it doesn't exist, create it and add it to the camper record.
else {
$brandObj = $modx->newObject('cmBrand');
// This file actually searches for the search term, and is being posted to on every character typed in
// Get the search query. Note that I put it in $search cause I already used $query as the xPDOQuery object
$search = $modx->getOption('query',$scriptProperties,'');
$query = $modx->newQuery('cmBrand');
// If there's a search request, tell modx to find it
if ($search !== '') {
'name:LIKE' => '%'.$search.'%'
//Output results as JSON
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment