admin管理员组文章数量:1026373
I would like to use the EasyAutplete plugin to create an autoplete list for the user and then to send the value associated to the matching string by GET method ... and not the matching string.
Using this code
<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery/jquery-1.11.2.min.js"></script>
<link rel="stylesheet" href="./EasyAutoplete/easy-autoplete.min.css">
<link rel="stylesheet" href="./EasyAutoplete/easy-autoplete.themes.min.css">
<script src="./EasyAutoplete/jquery.easy-autoplete.min.js"></script>
</head>
<body>
<form method="get" action="test.php">
<input id="provider-file" name="get_value"/>
<script>
$(document).ready(function() {
var options = {
url: "./EasyAutoplete/file.json",
getValue: "name",
list: {
match: {
enabled: true
}
}
};
$("#provider-file").easyAutoplete(options);
});
</script>
<div>
<a href=""><input type="submit" value="send"/></a>
</div>
</form>
</body>
</html>
and the JSON file having the following format
[
{"name":"Bob","id":"1"},
{"name":"David","id":"2"},
{"name":"Steve","id":"3"},
...
]
the user get redirected to 'test.php?get_value=Bob' after submitting Bob, while I would like him to be redirected to 'test.php?get_value=1' (i.e. to send "id" and not "name").
Could anyone help me? I couldn't find any answer in the EasyAutoplete doc.
I would like to use the EasyAutplete plugin to create an autoplete list for the user and then to send the value associated to the matching string by GET method ... and not the matching string.
Using this code
<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery./jquery-1.11.2.min.js"></script>
<link rel="stylesheet" href="./EasyAutoplete/easy-autoplete.min.css">
<link rel="stylesheet" href="./EasyAutoplete/easy-autoplete.themes.min.css">
<script src="./EasyAutoplete/jquery.easy-autoplete.min.js"></script>
</head>
<body>
<form method="get" action="test.php">
<input id="provider-file" name="get_value"/>
<script>
$(document).ready(function() {
var options = {
url: "./EasyAutoplete/file.json",
getValue: "name",
list: {
match: {
enabled: true
}
}
};
$("#provider-file").easyAutoplete(options);
});
</script>
<div>
<a href=""><input type="submit" value="send"/></a>
</div>
</form>
</body>
</html>
and the JSON file having the following format
[
{"name":"Bob","id":"1"},
{"name":"David","id":"2"},
{"name":"Steve","id":"3"},
...
]
the user get redirected to 'test.php?get_value=Bob' after submitting Bob, while I would like him to be redirected to 'test.php?get_value=1' (i.e. to send "id" and not "name").
Could anyone help me? I couldn't find any answer in the EasyAutoplete doc.
Share Improve this question asked Aug 29, 2016 at 16:13 RomainRomain 1412 silver badges9 bronze badges 2- perhaps changing the getValue: "name" to "id"? – celerno Commented Aug 29, 2016 at 16:15
- @celerno: actually not ... getValue also refers to the field to look into ... so changing getValue to "id" will induce no match for "Bob" or "David", ... But thanks. – Romain Commented Aug 29, 2016 at 16:17
1 Answer
Reset to default 5You can use the onSelectItemEvent
event along with the getSelectedItemData method to populate a hidden input field named get_value
with the ID you want to submit and remove the name from the lookup input field so that it won't get submitted.
HTML:
<input id="provider-file">
<input type="hidden" id="id-value" name="get_value">
Setup:
var options = {
url: "./EasyAutoplete/file.json",
getValue: "name",
list: {
onSelectItemEvent: function() {
var value = $("#provider-file").getSelectedItemData().id; //get the id associated with the selected value
$("#id-value").val(value).trigger("change"); //copy it to the hidden field
}
}
};
Demo (click submit to see that get_value=id is submitted):
$(document).ready(function() {
var options = {
data: [{
"name": "Bob",
"id": "1"
}, {
"name": "David",
"id": "2"
}, {
"name": "Steve",
"id": "3"
}],
getValue: "name",
list: {
onSelectItemEvent: function() {
var value = $("#provider-file").getSelectedItemData().id; //get the id associated with the selected value
$("#id-value").val(value).trigger("change"); //copy it to the hidden field
}
}
};
$("#provider-file").easyAutoplete(options);
// used to validate what gets submitted
$("#form-test").on('submit', function(e) {
e.preventDefault();
console.log($(this).serialize());
});
});
<script src="//code.jquery./jquery-1.11.2.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare./ajax/libs/easy-autoplete/1.3.5/easy-autoplete.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare./ajax/libs/easy-autoplete/1.3.5/easy-autoplete.themes.css">
<script src="https://cdnjs.cloudflare./ajax/libs/easy-autoplete/1.3.5/jquery.easy-autoplete.min.js"></script>
<form method="get" id="form-test">
<input id="provider-file">
<input type="hidden" id="id-value" name="get_value">
<input type="submit">
</form>
I would like to use the EasyAutplete plugin to create an autoplete list for the user and then to send the value associated to the matching string by GET method ... and not the matching string.
Using this code
<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery/jquery-1.11.2.min.js"></script>
<link rel="stylesheet" href="./EasyAutoplete/easy-autoplete.min.css">
<link rel="stylesheet" href="./EasyAutoplete/easy-autoplete.themes.min.css">
<script src="./EasyAutoplete/jquery.easy-autoplete.min.js"></script>
</head>
<body>
<form method="get" action="test.php">
<input id="provider-file" name="get_value"/>
<script>
$(document).ready(function() {
var options = {
url: "./EasyAutoplete/file.json",
getValue: "name",
list: {
match: {
enabled: true
}
}
};
$("#provider-file").easyAutoplete(options);
});
</script>
<div>
<a href=""><input type="submit" value="send"/></a>
</div>
</form>
</body>
</html>
and the JSON file having the following format
[
{"name":"Bob","id":"1"},
{"name":"David","id":"2"},
{"name":"Steve","id":"3"},
...
]
the user get redirected to 'test.php?get_value=Bob' after submitting Bob, while I would like him to be redirected to 'test.php?get_value=1' (i.e. to send "id" and not "name").
Could anyone help me? I couldn't find any answer in the EasyAutoplete doc.
I would like to use the EasyAutplete plugin to create an autoplete list for the user and then to send the value associated to the matching string by GET method ... and not the matching string.
Using this code
<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery./jquery-1.11.2.min.js"></script>
<link rel="stylesheet" href="./EasyAutoplete/easy-autoplete.min.css">
<link rel="stylesheet" href="./EasyAutoplete/easy-autoplete.themes.min.css">
<script src="./EasyAutoplete/jquery.easy-autoplete.min.js"></script>
</head>
<body>
<form method="get" action="test.php">
<input id="provider-file" name="get_value"/>
<script>
$(document).ready(function() {
var options = {
url: "./EasyAutoplete/file.json",
getValue: "name",
list: {
match: {
enabled: true
}
}
};
$("#provider-file").easyAutoplete(options);
});
</script>
<div>
<a href=""><input type="submit" value="send"/></a>
</div>
</form>
</body>
</html>
and the JSON file having the following format
[
{"name":"Bob","id":"1"},
{"name":"David","id":"2"},
{"name":"Steve","id":"3"},
...
]
the user get redirected to 'test.php?get_value=Bob' after submitting Bob, while I would like him to be redirected to 'test.php?get_value=1' (i.e. to send "id" and not "name").
Could anyone help me? I couldn't find any answer in the EasyAutoplete doc.
Share Improve this question asked Aug 29, 2016 at 16:13 RomainRomain 1412 silver badges9 bronze badges 2- perhaps changing the getValue: "name" to "id"? – celerno Commented Aug 29, 2016 at 16:15
- @celerno: actually not ... getValue also refers to the field to look into ... so changing getValue to "id" will induce no match for "Bob" or "David", ... But thanks. – Romain Commented Aug 29, 2016 at 16:17
1 Answer
Reset to default 5You can use the onSelectItemEvent
event along with the getSelectedItemData method to populate a hidden input field named get_value
with the ID you want to submit and remove the name from the lookup input field so that it won't get submitted.
HTML:
<input id="provider-file">
<input type="hidden" id="id-value" name="get_value">
Setup:
var options = {
url: "./EasyAutoplete/file.json",
getValue: "name",
list: {
onSelectItemEvent: function() {
var value = $("#provider-file").getSelectedItemData().id; //get the id associated with the selected value
$("#id-value").val(value).trigger("change"); //copy it to the hidden field
}
}
};
Demo (click submit to see that get_value=id is submitted):
$(document).ready(function() {
var options = {
data: [{
"name": "Bob",
"id": "1"
}, {
"name": "David",
"id": "2"
}, {
"name": "Steve",
"id": "3"
}],
getValue: "name",
list: {
onSelectItemEvent: function() {
var value = $("#provider-file").getSelectedItemData().id; //get the id associated with the selected value
$("#id-value").val(value).trigger("change"); //copy it to the hidden field
}
}
};
$("#provider-file").easyAutoplete(options);
// used to validate what gets submitted
$("#form-test").on('submit', function(e) {
e.preventDefault();
console.log($(this).serialize());
});
});
<script src="//code.jquery./jquery-1.11.2.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare./ajax/libs/easy-autoplete/1.3.5/easy-autoplete.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare./ajax/libs/easy-autoplete/1.3.5/easy-autoplete.themes.css">
<script src="https://cdnjs.cloudflare./ajax/libs/easy-autoplete/1.3.5/jquery.easy-autoplete.min.js"></script>
<form method="get" id="form-test">
<input id="provider-file">
<input type="hidden" id="id-value" name="get_value">
<input type="submit">
</form>
本文标签: javascriptEasyAutocomplete change the returned valueStack Overflow
版权声明:本文标题:javascript - EasyAutocomplete: change the returned value - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745643715a2160899.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论