Skip to content

Commit

Permalink
Merge pull request #6 from nyeholt/master
Browse files Browse the repository at this point in the history
FIX Item ordering and css class setting
  • Loading branch information
sheadawson committed Apr 1, 2015
2 parents 8690cae + f85a390 commit 3e4a9ed
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
23 changes: 18 additions & 5 deletions code/DependentDropdownField.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,28 @@ class DependentDropdownField extends DropdownField {

protected $depends;
protected $unselected;


public function __construct($name, $title = null, $source = array(), $value = '', $form = null, $emptyString = null) {
parent::__construct($name, $title, $source, $value, $form, $emptyString);

$this->addExtraClass('dependent-dropdown');
$this->addExtraClass('dropdown');
}

public function load($request) {
$response = new SS_HTTPResponse();
$response->addHeader('Content-Type', 'application/json');
$response->setBody(Convert::array2json(call_user_func(
$this->source, $request->getVar('val')
)));

$items = call_user_func($this->source, $request->getVar('val'));
$results = array();
if ($items) {
foreach ($items as $k => $v) {
$results[] = array('k' => $k, 'v' => $v);
}
}

$response->setBody(Convert::array2json($results));
return $response;
}

Expand Down Expand Up @@ -64,8 +79,6 @@ public function Field($properties = array()) {
Requirements::javascript(THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js');
Requirements::javascript(DEPENDENTDROPDOWNFIELD . '/javascript/dependentdropdownfield.js');

$this->addExtraClass('dependent-dropdown');
$this->addExtraClass('dropdown');
$this->setAttribute('data-link', $this->Link('load'));
$this->setAttribute('data-depends', $this->getDepends()->getName());
$this->setAttribute('data-empty', $this->getEmptyString());
Expand Down
4 changes: 2 additions & 2 deletions javascript/dependentdropdownfield.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ jQuery.entwine("dependentdropdown", function($) {
drop.append($("<option />").val("").text(drop.data('empty')))
}

$.each(data, function(k, v) {
drop.append($("<option />").val(k).text(v))
$.each(data, function() {
drop.append($("<option />").val(this.k).text(this.v))
});
drop.trigger("liszt:updated");
});
Expand Down

0 comments on commit 3e4a9ed

Please sign in to comment.