[Station Profiles] #847 from AndreasK79 dropdown for States and Counties
This provides a autocomplete for US counties based on the state provided.
这个提交包含在:
当前提交
c9f0544353
共有 5 个文件被更改,包括 3238 次插入 和 6 次删除
|
|
@ -135,4 +135,37 @@ class Station extends CI_Controller {
|
||||||
redirect('station');
|
redirect('station');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Function is used for autocompletion of Counties in the station profile form
|
||||||
|
*/
|
||||||
|
public function get_county() {
|
||||||
|
$json = [];
|
||||||
|
|
||||||
|
if(!empty($this->input->get("query"))) {
|
||||||
|
$query = isset($_GET['query']) ? $_GET['query'] : FALSE;
|
||||||
|
$county = $this->input->get("state");
|
||||||
|
|
||||||
|
$file = 'assets/json/US_counties.csv';
|
||||||
|
|
||||||
|
if (is_readable($file)) {
|
||||||
|
$lines = file($file, FILE_IGNORE_NEW_LINES);
|
||||||
|
$input = preg_quote($county, '~');
|
||||||
|
$reg = '~^'. $input .'(.*)$~';
|
||||||
|
$result = preg_grep($reg, $lines);
|
||||||
|
$json = [];
|
||||||
|
$i = 0;
|
||||||
|
foreach ($result as &$value) {
|
||||||
|
$county = explode(',', $value);
|
||||||
|
// Limit to 100 as to not slowdown browser too much
|
||||||
|
if (count($json) <= 100) {
|
||||||
|
$json[] = ["name"=>$county[1]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
echo json_encode($json);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -2785,6 +2785,55 @@ function deleteQsl(id) {
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<?php } ?>
|
||||||
|
|
||||||
|
<?php if ($this->uri->segment(1) == "station") { ?>
|
||||||
|
<script>
|
||||||
|
var baseURL= "<?php echo base_url();?>";
|
||||||
|
$('#StateHelp').change(function(){
|
||||||
|
var state = $("#StateHelp option:selected").text();
|
||||||
|
if (state != "") {
|
||||||
|
$("#stationCntyInput").prop('disabled', false);
|
||||||
|
|
||||||
|
$('#stationCntyInput').selectize({
|
||||||
|
maxItems: 1,
|
||||||
|
closeAfterSelect: true,
|
||||||
|
loadThrottle: 250,
|
||||||
|
valueField: 'name',
|
||||||
|
labelField: 'name',
|
||||||
|
searchField: 'name',
|
||||||
|
options: [],
|
||||||
|
create: false,
|
||||||
|
load: function(query, callback) {
|
||||||
|
var state = $("#StateHelp option:selected").text();
|
||||||
|
|
||||||
|
if (!query || state == "") return callback();
|
||||||
|
$.ajax({
|
||||||
|
url: baseURL+'index.php/station/get_county',
|
||||||
|
type: 'GET',
|
||||||
|
dataType: 'json',
|
||||||
|
data: {
|
||||||
|
query: query,
|
||||||
|
state: state,
|
||||||
|
},
|
||||||
|
error: function() {
|
||||||
|
callback();
|
||||||
|
},
|
||||||
|
success: function(res) {
|
||||||
|
callback(res);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$("#stationCntyInput").prop('disabled', true);
|
||||||
|
$('#stationCntyInput')[0].selectize.destroy();
|
||||||
|
$("#stationCntyInput").val("");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,8 @@
|
||||||
<small id="stationCityInputHelp" class="form-text text-muted">Station city. For example: Inverness</small>
|
<small id="stationCityInputHelp" class="form-text text-muted">Station city. For example: Inverness</small>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-row">
|
||||||
|
<div class="form-group col-sm-6">
|
||||||
<label for="stateInput">Station State</label>
|
<label for="stateInput">Station State</label>
|
||||||
<select class="form-control custom-select" name="station_state" id="StateHelp" aria-describedby="stationCntyInputHelp">
|
<select class="form-control custom-select" name="station_state" id="StateHelp" aria-describedby="stationCntyInputHelp">
|
||||||
<option value="" selected></option>
|
<option value="" selected></option>
|
||||||
|
|
@ -117,11 +118,12 @@
|
||||||
<small id="StateHelp" class="form-text text-muted">Station state. Applies to certain countries only. Leave blank if not applicable.</small>
|
<small id="StateHelp" class="form-text text-muted">Station state. Applies to certain countries only. Leave blank if not applicable.</small>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div style="display: none" class="form-group">
|
<div class="form-group col-sm-6">
|
||||||
<label for="stationCntyInput">Station County</label>
|
<label for="stationCntyInput">Station County</label>
|
||||||
<input type="text" class="form-control" name="station_cnty" id="stationCntyInput" aria-describedby="stationCntyInputHelp">
|
<input disabled="disabled" type="text" class="form-control" name="station_cnty" id="stationCntyInput" aria-describedby="stationCntyInputHelp">
|
||||||
<small id="stationCntyInputHelp" class="form-text text-muted">Station County (Only used for USA/Alaska/Hawaii)</small>
|
<small id="stationCntyInputHelp" class="form-text text-muted">Station County (Only used for USA/Alaska/Hawaii)</small>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<div class="form-group col-sm-6">
|
<div class="form-group col-sm-6">
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,8 @@
|
||||||
<small id="stationCityInputHelp" class="form-text text-muted">Station city. For example: Inverness</small>
|
<small id="stationCityInputHelp" class="form-text text-muted">Station city. For example: Inverness</small>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-row">
|
||||||
|
<div class="form-group col-sm-6">
|
||||||
<label for="stateInput">Station State</label>
|
<label for="stateInput">Station State</label>
|
||||||
<select class="form-control custom-select" name="station_state" id="StateHelp" aria-describedby="stationCntyInputHelp">
|
<select class="form-control custom-select" name="station_state" id="StateHelp" aria-describedby="stationCntyInputHelp">
|
||||||
<option value=""></option>
|
<option value=""></option>
|
||||||
|
|
@ -131,11 +132,12 @@
|
||||||
<small id="StateHelp" class="form-text text-muted">Station state. Applies to certain countries only. Leave blank if not applicable.</small>
|
<small id="StateHelp" class="form-text text-muted">Station state. Applies to certain countries only. Leave blank if not applicable.</small>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div style="display: none" class="form-group">
|
<div class="form-group col-sm-6">
|
||||||
<label for="stationCntyInput">Station County</label>
|
<label for="stationCntyInput">Station County</label>
|
||||||
<input type="text" class="form-control" name="station_cnty" id="stationCntyInput" aria-describedby="stationCntyInputHelp" value="<?php if(set_value('station_cnty') != "") { echo set_value('station_cnty'); } else { echo $my_station_profile->station_cnty; } ?>">
|
<input disabled="disabled" type="text" class="form-control" name="station_cnty" id="stationCntyInput" aria-describedby="stationCntyInputHelp" value="<?php if(set_value('station_cnty') != "") { echo set_value('station_cnty'); } else { echo $my_station_profile->station_cnty; } ?>">
|
||||||
<small id="stationCntyInputHelp" class="form-text text-muted">Station County (Only used for USA/Alaska/Hawaii)</small>
|
<small id="stationCntyInputHelp" class="form-text text-muted">Station County (Only used for USA/Alaska/Hawaii)</small>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<div class="form-group col-sm-6">
|
<div class="form-group col-sm-6">
|
||||||
|
|
|
||||||
3146
assets/json/US_counties.csv
普通文件
3146
assets/json/US_counties.csv
普通文件
文件差异内容过多而无法显示
加载差异
正在加载…
在新工单中引用