end
def before_validation
- # remove empty values
- self.possible_values = self.possible_values.collect{|v| v unless v.empty?}.compact
# make sure these fields are not searchable
self.searchable = false if %w(int float date bool).include?(field_format)
true
errors.add(:default_value, :activerecord_error_invalid) unless v.valid?
end
+ # Makes possible_values accept a multiline string
+ def possible_values=(arg)
+ if arg.is_a?(Array)
+ write_attribute(:possible_values, arg.compact.collect(&:strip).select {|v| !v.blank?})
+ else
+ self.possible_values = arg.to_s.split(/[\n\r]+/)
+ end
+ end
+
# Returns a ORDER BY clause that can used to sort customized
# objects by their value of the custom field.
# Returns false, if the custom field can not be used for sorting.
}
}
-function addValueField() {
- var f = $$('p#custom_field_possible_values span');
- p = document.getElementById("custom_field_possible_values");
- var v = f[0].cloneNode(true);
- v.childNodes[0].value = "";
- p.appendChild(v);
-}
-
-function deleteValueField(e) {
- var f = $$('p#custom_field_possible_values span');
- if (f.length == 1) {
- e.parentNode.childNodes[0].value = "";
- } else {
- Element.remove(e.parentNode);
- }
-}
-
//]]>
</script>
<%= f.text_field :min_length, :size => 5, :no_label => true %> -
<%= f.text_field :max_length, :size => 5, :no_label => true %><br>(<%=l(:text_min_max_length_info)%>)</p>
<p><%= f.text_field :regexp, :size => 50 %><br>(<%=l(:text_regexp_info)%>)</p>
-<p id="custom_field_possible_values"><label><%= l(:field_possible_values) %> <%= image_to_function "add.png", "addValueField();return false" %></label>
-<% (@custom_field.possible_values.to_a + [""]).each do |value| %>
-<span><%= text_field_tag 'custom_field[possible_values][]', value, :size => 30 %> <%= image_to_function "delete.png", "deleteValueField(this);return false" %><br /></span>
-<% end %>
-</p>
+<p id="custom_field_possible_values"><%= f.text_area :possible_values, :value => @custom_field.possible_values.to_a.join("\n"),
+ :cols => 20,
+ :rows => 15 %>
+<br /><em><%= l(:text_custom_field_possible_values_info) %></em></p>
<p><%= @custom_field.field_format == 'bool' ? f.check_box(:default_value) : f.text_field(:default_value) %></p>
</div>
text_plugin_assets_writable: Plugin assets directory writable
warning_attachments_not_saved: "%d file(s) could not be saved."
button_create_and_continue: Create and continue
+text_custom_field_possible_values_info: 'One line for each value'
text_plugin_assets_writable: Plugin assets directory writable\r
warning_attachments_not_saved: "%d file(s) could not be saved."\r
button_create_and_continue: Create and continue\r
+text_custom_field_possible_values_info: 'One line for each value'\r
text_plugin_assets_writable: Plugin assets directory writable
warning_attachments_not_saved: "%d file(s) could not be saved."
button_create_and_continue: Create and continue
+text_custom_field_possible_values_info: 'One line for each value'
text_plugin_assets_writable: Plugin assets directory writable
warning_attachments_not_saved: "%d file(s) could not be saved."
button_create_and_continue: Create and continue
+text_custom_field_possible_values_info: 'One line for each value'
text_plugin_assets_writable: Plugin assets directory writable
warning_attachments_not_saved: "%d file(s) could not be saved."
button_create_and_continue: Create and continue
+text_custom_field_possible_values_info: 'One line for each value'
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
text_repository_usernames_mapping: "Select or update the Redmine user mapped to each username found in the repository log.\nUsers with the same Redmine and repository username or email are automatically mapped."
text_diff_truncated: '... This diff was truncated because it exceeds the maximum size that can be displayed.'
+text_custom_field_possible_values_info: 'One line for each value'
default_role_manager: Manager
default_role_developper: Developer
text_plugin_assets_writable: Plugin assets directory writable
warning_attachments_not_saved: "%d file(s) could not be saved."
button_create_and_continue: Create and continue
+text_custom_field_possible_values_info: 'One line for each value'
text_plugin_assets_writable: Plugin assets directory writable
warning_attachments_not_saved: "%d file(s) could not be saved."
button_create_and_continue: Create and continue
+text_custom_field_possible_values_info: 'One line for each value'
text_email_delivery_not_configured: "L'envoi de mail n'est pas configuré, les notifications sont désactivées.\nConfigurez votre serveur SMTP dans config/email.yml et redémarrez l'application pour les activer."
text_repository_usernames_mapping: "Vous pouvez sélectionner ou modifier l'utilisateur Redmine associé à chaque nom d'utilisateur figurant dans l'historique du dépôt.\nLes utilisateurs avec le même identifiant ou la même adresse mail seront automatiquement associés."
text_diff_truncated: '... Ce différentiel a été tronqué car il excède la taille maximale pouvant être affichée.'
+text_custom_field_possible_values_info: 'Une ligne par valeur'
default_role_manager: Manager
default_role_developper: Développeur
text_diff_truncated: '... This diff was truncated because it exceeds the maximum size that can be displayed.'
warning_attachments_not_saved: "%d file(s) could not be saved."
button_create_and_continue: Create and continue
+text_custom_field_possible_values_info: 'One line for each value'
text_plugin_assets_writable: Plugin assets directory writable
warning_attachments_not_saved: "%d file(s) could not be saved."
button_create_and_continue: Create and continue
+text_custom_field_possible_values_info: 'One line for each value'
text_plugin_assets_writable: Plugin assets directory writable
warning_attachments_not_saved: "%d file(s) could not be saved."
button_create_and_continue: Create and continue
+text_custom_field_possible_values_info: 'One line for each value'
text_plugin_assets_writable: Plugin assets directory writable
warning_attachments_not_saved: "%d file(s) could not be saved."
button_create_and_continue: Create and continue
+text_custom_field_possible_values_info: 'One line for each value'
text_plugin_assets_writable: Plugin assets directory writable
warning_attachments_not_saved: "%d file(s) could not be saved."
button_create_and_continue: Create and continue
+text_custom_field_possible_values_info: 'One line for each value'
text_plugin_assets_writable: Plugin assets directory writable
warning_attachments_not_saved: "%d file(s) could not be saved."
button_create_and_continue: Create and continue
+text_custom_field_possible_values_info: 'One line for each value'
text_plugin_assets_writable: Plugin assets directory writable
warning_attachments_not_saved: "%d file(s) could not be saved."
button_create_and_continue: Create and continue
+text_custom_field_possible_values_info: 'One line for each value'
text_plugin_assets_writable: Plugin assets directory writable
warning_attachments_not_saved: "%d file(s) could not be saved."
button_create_and_continue: Create and continue
+text_custom_field_possible_values_info: 'One line for each value'
text_plugin_assets_writable: Plugin assets directory writable
warning_attachments_not_saved: "%d file(s) could not be saved."
button_create_and_continue: Create and continue
+text_custom_field_possible_values_info: 'One line for each value'
text_plugin_assets_writable: Plugin assets directory writable\r
warning_attachments_not_saved: "%d file(s) could not be saved."\r
button_create_and_continue: Create and continue\r
+text_custom_field_possible_values_info: 'One line for each value'\r
text_plugin_assets_writable: Plugin assets directory writable
warning_attachments_not_saved: "%d file(s) could not be saved."
button_create_and_continue: Create and continue
+text_custom_field_possible_values_info: 'One line for each value'
text_plugin_assets_writable: Plugin assets directory writable
warning_attachments_not_saved: "%d file(s) could not be saved."
button_create_and_continue: Create and continue
+text_custom_field_possible_values_info: 'One line for each value'
text_plugin_assets_writable: Plugin assets directory writable
warning_attachments_not_saved: "%d file(s) could not be saved."
button_create_and_continue: Create and continue
+text_custom_field_possible_values_info: 'One line for each value'
text_plugin_assets_writable: Plugin assets directory writable\r
warning_attachments_not_saved: "%d file(s) could not be saved."\r
button_create_and_continue: Create and continue\r
+text_custom_field_possible_values_info: 'One line for each value'\r
text_plugin_assets_writable: Plugin assets directory writable
warning_attachments_not_saved: "%d file(s) could not be saved."
button_create_and_continue: Create and continue
+text_custom_field_possible_values_info: 'One line for each value'
text_plugin_assets_writable: Plugin assets directory writable
warning_attachments_not_saved: "%d file(s) could not be saved."
button_create_and_continue: Create and continue
+text_custom_field_possible_values_info: 'One line for each value'
text_plugin_assets_writable: Plugin assets directory writable
warning_attachments_not_saved: "%d file(s) could not be saved."
button_create_and_continue: Create and continue
+text_custom_field_possible_values_info: 'One line for each value'
text_plugin_assets_writable: Plugin assets directory writable
warning_attachments_not_saved: "%d file(s) could not be saved."
button_create_and_continue: Create and continue
+text_custom_field_possible_values_info: 'One line for each value'
text_plugin_assets_writable: Plugin assets directory writable
warning_attachments_not_saved: "%d file(s) could not be saved."
button_create_and_continue: Create and continue
+text_custom_field_possible_values_info: 'One line for each value'
text_plugin_assets_writable: Plugin assets directory writable\r
warning_attachments_not_saved: "%d file(s) could not be saved."\r
button_create_and_continue: Create and continue\r
+text_custom_field_possible_values_info: 'One line for each value'\r
text_plugin_assets_writable: Plugin assets directory writable
warning_attachments_not_saved: "%d file(s) could not be saved."
button_create_and_continue: Create and continue
+text_custom_field_possible_values_info: 'One line for each value'
text_plugin_assets_writable: Plugin assets directory writable
warning_attachments_not_saved: "%d file(s) could not be saved."
button_create_and_continue: Create and continue
+text_custom_field_possible_values_info: 'One line for each value'
assert field.save
end
+ def test_possible_values_should_accept_an_array
+ field = CustomField.new
+ field.possible_values = ["One value", ""]
+ assert_equal ["One value"], field.possible_values
+ end
+
+ def test_possible_values_should_accept_a_string
+ field = CustomField.new
+ field.possible_values = "One value"
+ assert_equal ["One value"], field.possible_values
+ end
+
+ def test_possible_values_should_accept_a_multiline_string
+ field = CustomField.new
+ field.possible_values = "One value\nAnd another one \r\n \n"
+ assert_equal ["One value", "And another one"], field.possible_values
+ end
+
def test_destroy
field = CustomField.find(1)
assert field.destroy