Dear Scott,
Here are both cases in the same shortcode I call in a page:
$mypod = pods( 'pod_type' );
$fields = array( 'post_title');
echo $mypod->form( $fields );
// Autocomplete on an html input field -> works
echo <<<EOT1
<!DOCTYPE html>
<html>
<body>
<input type="text" id="autocomplete_id" name="pods_field_name">
<script src="https://cdn.jsdelivr.net/npm/@tarekraafat/[email protected]/dist/autoComplete.min.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function() {
const autoCompleteJS = new autoComplete({
selector: "#autocomplete_id",
placeHolder: "Search for Food...",
data: {
src: ["Sauce - Thousand Island", "Wild Boar - Tenderloin", "Goat - Whole Cut"],
cache: true,
},
resultItem: {
highlight: true
},
events: {
input: {
selection: (event) => {
const selection = event.detail.selection.value;
autoCompleteJS.input.value = selection;
}
}
}
});
});
</script>
</body>
</html>
EOT1;
// Autocomplete on a pod form field -> I can't make it work
echo <<<EOT2
<!DOCTYPE html>
<html>
<body>
<script src="https://cdn.jsdelivr.net/npm/@tarekraafat/[email protected]/dist/autoComplete.min.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function() {
var titleInput = document.getElementById("pods-form-ui-pods-field-name");
const autoCompleteJS = new autoComplete({
selector: titleInput,
placeHolder: "Search for Food...",
data: {
src: ["Sauce - Thousand Island", "Wild Boar - Tenderloin", "Goat - Whole Cut"],
cache: true,
},
resultItem: {
highlight: true
},
events: {
input: {
selection: (event) => {
const selection = event.detail.selection.value;
autoCompleteJS.input.value = selection;
}
}
}
});
});
</script>
</body>
</html>
EOT2;
The only difference is the selector:
<input type="text" id="autocomplete_id" name="pods_field_name">
[...]
selector: "#autocomplete_id",
which becomes:
var titleInput = document.getElementById("pods-form-ui-pods-field-name");
[...]
selector: titleInput,
As I write these lines, I can see in the autoComplete.js website this: “Works on anything (<input>
, <textarea>
and contentEditable
elements)”
Could this be the core issue ? Is there any way to make it work together ?
Thanks a lot !
Xerviami
-
This reply was modified 10 months, 4 weeks ago by xerviami.
-
This reply was modified 10 months, 4 weeks ago by xerviami.