Skip to content

Commit

Permalink
ks filter: FilterInput interface
Browse files Browse the repository at this point in the history
  • Loading branch information
alex40724 committed Oct 15, 2018
1 parent b411ae1 commit aeb96f4
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 8 deletions.
33 changes: 33 additions & 0 deletions src/UI/Component/Input/Field/FilterInput.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */

namespace ILIAS\UI\Component\Input\Field;

/**
* This interface must be implemented by all Inputs that support
* Filter Containers.
*
* These inputs need to implement an additional rendering in the
* FilterContextRenderer and provide an additional method that allows
* the Filter to show the current selected values within the Filter component.
*
* @author [email protected]
*/
interface FilterInput extends Input {

/**
* Get update code
*
* This method has to return JS code that calls
* il.UI.filter.handleChange(event, '$id', string_value);
* - initially "onload" and
* - on every input change.
* It must pass a readable string representation of its value in parameter 'string_value'.
*
* @param \Closure $binder
* @return string
*/
public function getUpdateOnLoadCode(): \Closure;

}
2 changes: 1 addition & 1 deletion src/UI/Component/Input/Field/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
/**
* This describes text inputs.
*/
interface Text extends Input {
interface Text extends FilterInput {

}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function __construct($toggle_action_on, $toggle_action_off, $expand_actio
if (count($inputs) != count($is_input_rendered)) {
throw new \ArgumentCountError("Inputs and boolean values must be arrays of same size.");
} else {
$classes = [CI\Input\Field\Input::class];
$classes = ['\ILIAS\UI\Component\Input\Field\FilterInput'];
$this->checkArgListElements("input", $inputs, $classes);

// @todo: how to manage this dependency?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,7 @@ protected function renderInputField(Template $tpl, Input $input) {
$tpl->parseCurrentBlock();
}

$input = $input->withAdditionalOnLoadCode(function ($id) {
$code = "$('#$id').on('input', function(event) {
il.UI.filter.handleChange(event, '$id', $('#$id').val());
});";
return $code;
});
$input = $input->withAdditionalOnLoadCode($input->getUpdateOnLoadCode());
$this->maybeRenderId($input, $tpl);
break;
}
Expand Down
13 changes: 13 additions & 0 deletions src/UI/Implementation/Component/Input/Field/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,17 @@ protected function isClientSideValueOk($value) {
protected function getConstraintForRequirement() {
return $this->validation_factory->hasMinLength(1);
}

/**
* @inheritdoc
*/
public function getUpdateOnLoadCode(): \Closure
{
return function ($id) {
$code = "$('#$id').on('input', function(event) {
il.UI.filter.handleChange(event, '$id', $('#$id').val());
});";
return $code;
};
}
}

0 comments on commit aeb96f4

Please sign in to comment.