Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix required setting and force user to pick value when required #6

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions assets/publish.remote_selectbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
if (!!data && !!data.length) {
var options = [];
var selectedValue = t.attr('data-value');
var required = ~~t.attr('data-required');

if (required) {
t.empty();
}

$.each(data, function (index, d) {
var o = $('<option />')
Expand All @@ -43,4 +38,4 @@

$(init);

})(jQuery);
})(jQuery);
15 changes: 15 additions & 0 deletions fields/field.remote_selectbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,21 @@ public function displayPublishPanel(XMLElement &$wrapper, $data = null, $flagWit
if($flagWithError != null) $wrapper->appendChild(Widget::Error($label, $flagWithError));
else $wrapper->appendChild($label);
}

public function checkPostFieldData($data, &$message, $entry_id = null)
{
$message = null;

$has_no_value = is_array($data) ? empty($data['value']) : strlen(trim($data)) == 0;

if ($this->get('required') === 'yes' && $has_no_value) {
$message = __('‘%s’ is a required field.', array($this->get('label')));

return self::__MISSING_FIELDS__;
}

return self::__OK__;
}

public function processRawFieldData($data, &$status, &$message=null, $simulate=false, $entry_id=NULL){
$status = self::__OK__;
Expand Down