1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| <%= form_for(@incident) do |f| %>
<% if @incident.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@incident.errors.count, "error") %> prohibited this incident from being saved:</h2>
<ul>
<% @incident.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label "Titre" %><br>
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label "Contenu" %><br>
<%= f.text_field :content %>
</div>
<div class="field" style="display: none;">
<%= f.label "Nom d'utilisateur" %><br>
<%= select_tag("incident[user_id]", options_for_select(User.find_by_sql("SELECT `users`.* FROM `users` WHERE `id` = #{current_user.id}").collect{ |u| [u.name, u.id]})) %>
</div>
<div class="field">
<%= f.label "Catégorie de l'incident" %><br>
<%= cat_select = select_tag("incident[category_id]", options_for_select(Category.find_by_sql("SELECT `categories`.* FROM `categories`").collect{ |u| [u.name, u.id]}))%>
</div>
<div id="field">
<%= f.label "Sous_Catégorie de l'incident" %><br>
<%= cat_select = select_tag("incident[sous_category_id]", options_for_select(SousCategory.find_by_sql("SELECT `sous_categories`.* FROM `sous_categories` ").collect{ |u| [u.name, u.id]}))%>
</div>
<div class="field" style="display: none;">
<%= f.label "Type de l'évenement"%>
<%= f.number_field :evenement_type_id, :value => 1 %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
<!--
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.1.min.js" /></script>
<script type="text/javascript">
$('#incident_category_id').on('change', function() { //WHEN USER CHANGES FIRST OPTION
var fromVal = $(this).val(); //MAKE VARIABLE OF SELECTED CHOICE
document.write("Test");
var myDiv = document.getElementById("field");
//Create array of options to be added
foreach($db->query("SELECT * FROM sous_categories WHERE categorie_id = '$fromVal'") as $row) {
};
var array = ["Volvo","Saab","Mercades","Audi"];
//Create and append select list
var selectList = document.createElement("select");
selectList.id = ("incident_sous_category_id");
myDiv.appendChild(selectList);
//Create and append the options
for (var i = 0; i < array.length; i++) {
var option = document.createElement("option");
option.setAttribute("value", array[i]);
option.text = array[i];
selectList.appendChild(option);
});
});
});
</script>
</script>
--> |
Partager