Skip to content

Commit

Permalink
Fix styles, add new params, remove init script (#9)
Browse files Browse the repository at this point in the history
* Remove invalid css styles and add new params

* fix wrap class params and add new param for disabel all wrap classes
  • Loading branch information
distroid authored Sep 27, 2017
1 parent 199c24f commit 8d75126
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 17 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ Script automaticly will be replace `{{id}}` param to selected value.
`label` | string | From object
`value` | mixed | From object
`placeholder` | string | --
`wrap_class` | string | --
`wrap_class` | string \| false | --
`wrap_class_only` | true \| false | false
`label_class` | string | --
`input_html[class]` | string | --
`required` | true \| false | From object
Expand Down
5 changes: 3 additions & 2 deletions app/assets/javascripts/selectize-ajax.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ window.SelectizeAjax = class SelectizeAjax
$(@options.add_modal).on 'hidden.bs.modal, show.bs.modal', ->
$(this).find('form')[0].reset() if $(this).find('form').length > 0

$('.error').each ->
$(this).find('.error').each ->
$(this).remove()

$('.field_with_errors').each ->
$(this).find('.field_with_errors').each ->
$(this).removeClass 'field_with_errors'

ajax_edit_complete_script: () ->
Expand All @@ -112,6 +112,7 @@ window.SelectizeAjax = class SelectizeAjax
.closest('.selectize-ajax-wrapper')
.addClass('selectize-ajax-wrapper--empty')
else
$(".edit-#{@options.resource_id}").show()
$(".edit-#{@options.resource_id}").attr(
'href',
@options.edit_resource_template.replace('{{id}}', $("##{@options.resource_id}").val())
Expand Down
9 changes: 0 additions & 9 deletions app/assets/stylesheets/selectize-ajax.css
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
.input-group-btn .btn-remote {
}

.selectize-input-group {
position: relative;
display: table;
border-collapse: separate;
}

.selectize-ajax-wrapper {
position: relative;
display: flex;
align-items: flex-end;
}

.selectize-ajax-wrapper.form-group {
flex: 1;
margin-left: 0;
Expand Down
3 changes: 2 additions & 1 deletion app/views/selectize_ajax/_tag.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
<% if control.can_edit? %>
<%= link_to control.options.edit_path,
class: "btn btn-primary btn-remote edit-#{control.resource_id} #{control.options.edit_button_class}",
data: { toggle: 'modal', target: control.options.edit_modal } do %>
data: { toggle: 'modal', target: control.options.edit_modal },
style: ('display:none;' if control.value.blank?) do %>
<span class="glyphicon glyphicon-edit"></span>
<%= control.options.edit_button_text %>
<% end %>
Expand Down
5 changes: 4 additions & 1 deletion lib/selectize/ajax/core/control.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,13 @@ def field_required?
end

def wrap_classes
return if options.wrap_class == false
return options.wrap_class if options.wrap_class_only

classes = [options.wrap_class]
classes << 'selectize-input-group' if can_add?
classes << (options.horizontal ? 'col-sm-9' : 'col-sm-12')
classes.reject!(&:blank?).join(' ')
classes.compact.reject(&:blank?).join(' ')
end

def has_error?
Expand Down
5 changes: 3 additions & 2 deletions lib/selectize/ajax/core/script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ def call
private

def js_script_tag
"<script type=\"text/javascript\">
$(function(event) {
"<script type=\"text/javascript\" id=\"sj-#{control.resource_id}-script\">
$(function() {
setTimeout(function() {
obj = new window.SelectizeAjax(#{tag_options.to_json});
SJCollection['#{control.resource_id}'] = obj;
$('#sj-#{control.resource_id}-script').remove();
});
});
</script>"
Expand Down
1 change: 1 addition & 0 deletions lib/selectize/ajax/core/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def default_options
search_param: 'q',
placeholder: nil,
wrap_class: '',
wrap_class_only: false,
label_class: '',
add_button_class: '',
edit_button_class: '',
Expand Down
2 changes: 1 addition & 1 deletion lib/selectize/ajax/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Selectize
module Ajax
VERSION = "0.1.7"
VERSION = "0.1.8"
end
end

0 comments on commit 8d75126

Please sign in to comment.