Portal : Autocomplete bug with IE9 in forms

SVN:trunk[4424]
This commit is contained in:
Guillaume Lajarige
2016-09-29 10:16:30 +00:00
parent b7d101cdfb
commit 88eece7188

View File

@@ -78,7 +78,7 @@ class BsSelectObjectFieldRenderer extends FieldRenderer
//$bRegularSelect = ($iSetCount <= $this->oField->GetMaximumComboLength()); //$bRegularSelect = ($iSetCount <= $this->oField->GetMaximumComboLength());
$bRegularSelect = ( ($iSetCount <= $this->oField->GetMaximumComboLength()) || ($this->oField->GetSearchEndpoint() === null) || ($this->oField->GetSearchEndpoint() === '') ); $bRegularSelect = ( ($iSetCount <= $this->oField->GetMaximumComboLength()) || ($this->oField->GetSearchEndpoint() === null) || ($this->oField->GetSearchEndpoint() === '') );
unset($oCountSet); unset($oCountSet);
// - For regular select // - For regular select
if ($bRegularSelect) if ($bRegularSelect)
{ {
@@ -245,48 +245,54 @@ EOF
} }
}); });
$('#$sAutocompleteFieldId').typeahead({ // This check is only for IE9... Otherwise the widget is duplicated on the field causing misbehaviour.
hint: true, if($('#$sAutocompleteFieldId').typeahead('val') === undefined)
hightlight: true, {
minLength: {$this->oField->GetMinAutoCompleteChars()} $('#$sAutocompleteFieldId').typeahead({
},{ hint: true,
name: '{$this->oField->GetId()}', hightlight: true,
source: oAutocompleteSource_{$this->oField->GetId()}, minLength: {$this->oField->GetMinAutoCompleteChars()}
limit: 20, },{
display: 'name', name: '{$this->oField->GetId()}',
templates: { source: oAutocompleteSource_{$this->oField->GetId()},
suggestion: Handlebars.compile('<div>{{name}}</div>'), limit: 20,
pending: $("#page_overlay .content_loader").prop('outerHTML'), display: 'name',
notFound: '<div class="no_result">{$sNoResultText}</div>' templates: {
} suggestion: Handlebars.compile('<div>{{name}}</div>'),
}) pending: $("#page_overlay .content_loader").prop('outerHTML'),
.off('typeahead:select').on('typeahead:select', function(oEvent, oSuggestion){ notFound: '<div class="no_result">{$sNoResultText}</div>'
$('#{$this->oField->GetGlobalId()}').val(oSuggestion.id);
// Triggering set_current_value event
var oValue = {};
oValue[oSuggestion.id] = oSuggestion.name;
$("[data-field-id='{$this->oField->GetId()}'][data-form-path='{$this->oField->GetFormPath()}']").trigger('set_current_value', {value: oValue});
})
.off('typeahead:change').on('typeahead:change', function(oEvent, oSuggestion){
// Checking if the value is a correct value. This is necessary because the user could empty the field / remove some chars and typeahead would not update the hidden input
var oDatums = oAutocompleteSource_{$this->oField->GetId()}.index.datums;
var bFound = false;
for(var i in oDatums)
{
if(oDatums[i].name == oSuggestion)
{
bFound = true;
$('#{$this->oField->GetGlobalId()}').val(oDatums[i].id);
break;
} }
} })
// Emptying the fields if value is incorrect .off('typeahead:select').on('typeahead:select', function(oEvent, oSuggestion){
if(!bFound) $('#{$this->oField->GetGlobalId()}').val(oSuggestion.id);
{ $('#{$sAutocompleteFieldId}').val(oSuggestion.name);
$('#{$this->oField->GetGlobalId()}').val(0); // Triggering set_current_value event
$('#{$sAutocompleteFieldId}').val(''); var oValue = {};
} oValue[oSuggestion.id] = oSuggestion.name;
}); $("[data-field-id='{$this->oField->GetId()}'][data-form-path='{$this->oField->GetFormPath()}']").trigger('set_current_value', {value: oValue});
})
.off('typeahead:change').on('typeahead:change', function(oEvent, oSuggestion){
// Checking if the value is a correct value. This is necessary because the user could empty the field / remove some chars and typeahead would not update the hidden input
var oDatums = oAutocompleteSource_{$this->oField->GetId()}.index.datums;
var bFound = false;
for(var i in oDatums)
{
if(oDatums[i].name == oSuggestion)
{
bFound = true;
$('#{$this->oField->GetGlobalId()}').val(oDatums[i].id);
$('#{$sAutocompleteFieldId}').val(oDatums[i].name);
break;
}
}
// Emptying the fields if value is incorrect
if(!bFound)
{
$('#{$this->oField->GetGlobalId()}').val(0);
$('#{$sAutocompleteFieldId}').val('');
}
});
}
EOF EOF
); );
} }