How to make a radio button in Jquery UI? - jquery-ui

How can I make the check box a radio button? I want to add a radio button before By buffer and By polygon.
dialog1.empty();
var header = $('<h5></h5>').text('By buffer');
var toggleBtn = $('<button><i id="toggle-icon" class="fa fa-circle"></i></button>').attr('id', 'toggle-buffer-btn').attr('class', 'btn btn-default btn-sm');
var inputRadius = $('<input type="text"/>').attr('id', 'radius').attr('class', 'btn btn-default btn-sm').attr('disabled', 'disabled');
var helpLabel = $('<span id="help-label">Click and drag mouse to create buffer</span>');
var polyBufferChkbx = $('<input type="checkbox">').attr('id', 'polygon-buffer');
var polyBufferLabel = $('<span id="polygon-buffer-label"> &nbsp By polygon</span>');
var val;
dialog1.append(header);
dialog1.append(toggleBtn);
dialog1.append(inputRadius);
dialog1.append(helpLabel);
dialog1.append('<br/>');
dialog1.append('<br/>');
dialog1.append(polyBufferChkbx);
dialog1.append(polyBufferLabel);

If you're going to use jQuery UI, why not let it help you.
Example: https://jsfiddle.net/Twisty/wfqv3orm/
HTML
<div id="dialog1">
</div>
JavaScript
$(function() {
var dialog1 = $("#dialog1");
dialog1.empty();
var header = $("<h5>", {
class: "dialog-header"
}).text("By buffer").appendTo(dialog1);
$("<button>", {
id: "toggle-buffer-btn",
class: "btn btn-default btn-sm"
}).appendTo(dialog1);
dialog1.find("button").append($("<i>", {
id: "toggle-icon",
class: "fa fa-circle"
}));
$("<input>", {
type: "text",
id: "radius",
class: 'btn btn-default btn-sm'
}).prop('disabled', true).appendTo(dialog1);
$("<span>", {
id: "help-label",
style: "margin-bottom: 2em;"
}).html("Click and drag mouse to create buffer").appendTo(dialog1);
$("<input>", {
type: "checkbox",
id: 'polygon-buffer'
}).appendTo(dialog1);
$("<label>", {
id: "polygon-buffer-label",
for: "polygon-buffer"
}).html("By polygon").appendTo(dialog1);
dialog1.controlgroup();
var val;
});
Little bit faster to just build and append elements all at once in my opinion.

Related

I want to add if condition in kendo ui gridview Nopcommerce

{
field: "Id",
title: "#T("Admin.Common.Download")",
width: 100,
headerAttributes: { style: "text-align:center" },
attributes: { style: "text-align:center" },
template: '<a class="btn btn-default" href="DownloadPdf/?downloadGuid=#=downloadGuid#" title="Download" ><i class="fa fa-download" aria-hidden="true"></i></a>'
}
in template section I need if downloadGuid is not empty then Download icon will show otherwise not.
If we want to add If else condition in kendo grid we want to add # before and after condition.
template: '#if (downloadGuid!=null) { #<a class="btn btn-default" href="DownloadPdf/?downloadGuid=#=downloadGuid#" title="Download" ><i class="fa fa-download" aria-hidden="true"></i></a> # }#'

Rails 5: Combine a normal form with vue2-dropzone

I'm trying to combine a normal form with vue2-dropzone in a Rails 5 app I'm working on.
I think I've almost gotten it to work but the form data isn't being sent across with the Dropzone images.
My _form.html.erb looks a bit like this:
<%= form_for(listing, html: { multipart: true, id: 'listing_form', data: { listing: listing.to_json } }) do |f| %>
<div class="row">
<div class="col">
<div class="form-group">
<strong><%= f.label :address %></strong><br>
<%= f.text_field :address, class: 'form-control', 'v-model': 'address' %>
</div>
</div>
</div>
<!-- Other input fields here -->
<div class="row">
<div class="col">
<h2>Images</h3>
<vue-dropzone
ref="listingDropzone"
id="dropzone"
#vdropzone-success-multiple="listingRedirect"
:options="dropzoneOptions">
</vue-dropzone>
</div>
</div>
<%= f.submit class: 'btn btn-success', 'v-on:click.stop.prevent': 'submitListing' %>
<% end %>
I am submitting the data with the submitListing which I define in a Vue method. That, in turn, calls Dropzone's processQueue which handles the submission. listingRedirect Is then called to perform redirection on success.
if(document.getElementById('listing-multistep') != null) {
Vue.http.headers.common['X-CSRF-Token'] = document.querySelector('input[name="authenticity_token"]').getAttribute('value');
var listingForm = document.getElementById('listing_form');
var listing = JSON.parse(listingForm.dataset.listing);
const myForm = new Vue({
el: '#listing-multistep',
components: {
vueDropzone: vue2Dropzone
},
data: function () {
return {
id: listing.id,
// Other options here...
address: listing.address,
dropzoneOptions: {
url: '/listings',
method: 'post',
acceptedFiles: 'image/*',
uploadMultiple: true,
autoProcessQueue: false, // Dropzone should wait for the user to click a button to upload
parallelUploads: 15, // Dropzone should upload all files at once (including the form data) not all files individually
maxFiles: 15, // this means that they shouldn't be split up in chunks
addRemoveLinks: true,
thumbnailWidth: 150,
maxFilesize: 5,
dictDefaultMessage: "<i class='fa fa-cloud-upload'></i> Drop files here to upload (max. 15 files)",
headers: { 'X-CSRF-Token': Vue.http.headers.common['X-CSRF-Token'] }
}
}
},
mounted: function() {
// Dropzone actually performs the form submission.
// Make a PUT request if the listing id exists.
if(this.id !== null) {
this.dropzoneOptions['url'] = `/listings/${this.id}`
this.dropzoneOptions['method'] = 'put'
}
},
methods: {
submitListing: function() {
// Do some form processing...
// listingObj contains the rest of the form data.
// I'd like to send this object across in the payload.
var listingObj = {
address: this.address,
// more fields...
}
this.$refs.listingDropzone.processQueue()
},
listingRedirect: function(files, response) {
window.location = `/listings/${response.body.id}`
}
}
})
I can see the image being sent across in the controller. The problem is that none of the other form data is being sent. What am I doing wrong here?
Thanks in advance!

Ant Design - prevent table row click in specific column/area

I'm using ant design table component. I have "actions" column that I don't want the onRowClick event will trigger in this column.
How can it be done?
http://codepen.io/liron_e/pen/zZjVKZ?editors=001
const { Table, Modal } = antd;
const confirm = (id) => {
Modal.confirm({
title: 'Confirm',
content: 'Bla bla ...',
okText: 'OK',
cancelText: 'Cancel',
});
};
const info = (id) => {
Modal.info({
title: 'Info',
content: 'Bla bla ...',
okText: 'OK',
cancelText: 'Cancel',
});
};
const columns = [
{
key: 'status',
title: 'text',
dataIndex: 'text'
}, {
key: 'actions',
title: 'actions',
dataIndex: 'id',
render: (id) => {
return (
<span>
<a href="#" onClick={() => confirm(id)}>
Clone
</a>
<span className="ant-divider" />
<a href="#" onClick={() => confirm(id)}>
Replace
</a>
</span>
);
}
}
];
const dataSource = [
{
id: '1',
text: 'Hello'
},{
id: '123',
text: 'adsaddas'
},{
id: '123344',
text: 'cvbbcvb'
},{
id: '5665',
text: 'aasddasd'
},
];
ReactDOM.render(
<div>
<Table
columns={columns}
onRowClick={() => this.info()}
dataSource={dataSource}
/>
</div>
, mountNode);
As you can try when pressing on row the info modal would open.
When pressing some action the info and the confirm modals would open, and I would like that only confirm modal would open.
Thanks (:
In your render function:
render: (id) => {
return (
<span>
<a href="#" onClick={(e) => {
e.stopPropagation();
confirm(id);
}}>
Clone
</a>
<span className="ant-divider" />
<a href="#" onClick={() => confirm(id)}>
Replace
</a>
</span>
);
}
Just stop propagation in your action handler:
<span>
<a href="#" onClick={() => confirm(id)}>
Clone
</a>
<span className="ant-divider" />
<a href="#" onClick={() => confirm(id)}>
Replace
</a>
</span>
<Menu.Item onClick={(e)=>{
e.domEvent.stopPropagation();
handleUpdate(id)}}>
Edit
</Menu.Item>
Using react Link we can have a default anchor link functionality by stoping event propagation and trigger event on particular column.
"react-router": "^5.2.0",
import { Link } from "react-router-dom";
render: (value, record) => {
// Conditional checks if needs to handle on particular set of column
return (
<Link to={'TARGET_LINK_HERE'}
target="_blank" rel="noopener noreferrer"
onClick={(event) => {
event.stopPropagation(); // prevent event to propogate to parent to have row click which is default functionality
}}>{value}</Link>
)
}

Algolia Typeahead retrieve results

I am trying to create a discussion tool in my Rails app. I'd like to add users to a discussion like in Facebook messenger.
To do so, I implemented Algolia instant search sith Typeahead. It works fine to show th results but when I click on a result it does nothing at all. It looks like if the event I am using was not working.
I cannot use my keyboard to go up or down the results, it's very strange. Could you help me? I tried all the events on the Typeahead documentation but no one is working.
Thank you so much.
<div class="uk-grid message">
<div class="uk-width-medium-2-6"></div>
<div class="uk-width-medium-3-6 bubble">
<%= form_tag create_discussion_path, method: :post, remote: true, class: 'uk-form', id: 'createDiscussionForm' do %>
<div class="form-group">
<div class="uk-grid">
<div class="uk-width-1-6">
<span><%= t('to') %></span>
</div>
<div class="uk-width-5-6">
<%= text_field_tag 'recipients', '', class: 'recipients typeahead', id: 'typeahead-algolia-template', spellcheck: false %>
</div>
</div>
<%= text_area_tag 'body', nil, cols: 3, class: 'form-control uk-width-1-1 body', placeholder: 'Ask something or just say hi!', required: true %>
</div>
<%= submit_tag t('dashboard.discussions.send_message'), class: 'uk-button uk-width-1-1' %>
<% end %>
<div class="arrow-right"></div>
</div>
<div class="uk-width-medium-1-6 text-center">
<%= link_to user_path(current_user) do %>
<%= image_tag(current_user.pictures.first.image(:square_thumb)) %>
<% end %>
<p><%= current_user.first_name %></p>
</div>
</div>
<!-- Algolia search callback -->
<script type="text/javascript">
function searchCallback(success, content) {
if (content.query != $("#typeahead-algolia-template").val()) {
// do not take out-dated answers into account
return;
}
if (content.hits.length == 0) {
// no results
$('#hits').empty();
return;
}
} // end search callback
</script>
<!-- end Algolia search callback -->
<!-- Algolia with typehead and hogan -->
<script type="text/javascript">
$(document).ready(function() {
// Algolia initialization
var $inputfield = $("#typeahead-algolia-template");
var algolia = algoliasearch('<%= ENV['ALGOLIA_ID'] %>', '<%= ENV['ALGOLIA_PUBLIC_KEY'] %>');
var index = algolia.initIndex('<%= 'User_' + Rails.env %>');
var ttAdapterParams = {
hitsPerPage: 5,
facets: '*',
tagFilters: ''
};
// Templating
var templates = {
algolia: {
hit: Hogan.compile(
'<div class="uk-grid">' +
'<div class="uk-width-1-4">' +
'<img src="{{{_highlightResult.picture.value}}}">' +
'</div>' +
'<div class="uk-width-3-4">' +
'<span class="name">' +
'{{{_highlightResult.first_name.value}}}, ' +
'</span>' +
'<span class="occupation">' +
'{{{_highlightResult.occupation.value}}}' +
'</span>' +
'</div>' +
'</div>'
)
}
};
// Search?
$inputfield.typeahead({
highlight: true,
hint: true,
minLength: 1
},
{
source: index.ttAdapter(ttAdapterParams),
displayKey: 'name',
templates: {
suggestion: function(hit) {
var tpl = templates.algolia.hit.render(hit);
//console.log(tpl, 'hit');
return tpl;
}
}
}).on('typeahead:open', function(event, data) {
// var $form = $(this).closest('form');
// $form.data('sendToServer', true);
// $form.submit();
});
var val = $inputfield.typeahead('val');
console.log(val);
$("#typeahead-algolia-template").bind('typeahead:open', function(ev, suggestion) {
console.log('Selection: ' + suggestion);
});
});
</script>
Thanks to the great Algolia support team I managed to make it work!
As suggested, I switched to https://github.com/algolia/autocomplete.js and it's just perfect. I changed a few things, basically replacing .typeahead by .autocomplete and the event listener name.
Here is the snippet:
$inputfield.autocomplete({
highlight: true,
autoselect: true,
openOnFocus: true
}, [
{
source: $.fn.autocomplete.sources.hits(index, ttAdapterParams),
displayKey: 'first_name',
templates: {
suggestion: function(hit) {
var tpl = templates.algolia.hit.render(hit);
//console.log(tpl, 'hit');
return tpl;
}
}
}]).on('autocomplete:selected', function(event, suggestion, dataset) {
console.log(suggestion);
});

Binding backbone collection to view and underscore template on front end

I am using backbone + jquery mobile and couldn't get my array of models (collections) to output to the UI via underscore template.
My model is as follows:
var shortcake = Backbone.Model.extend({
defaults: function() {
return {
name: "No Slot",
butter: false,
time: "3pm",
icon: "plus",
deladd: "ADD"
};
},
initialize: function() {
this.bind("change:butter", function(){
if (this.model.butter == false) {
this.set({name: this.defaults.name});
};
}),
}
});
My collection is as follows:
var shortcakes = Backbone.Collection.extend ({
model: shortcake
});
var shortcake1 = new shortcake({ name: "How Bizarre", butter: "true", time: "1", icon:"plus", deladd:"ADD" });
var shortcake2 = new shortcake({ name: "Sexual Healing", butter: "true", time: "1", icon:"plus", deladd:"ADD" });
var shortcakeAlbum = new shortcakes([ shortcake1, shortcake2]);
And my view:
var shortcakeUI = Backbone.View.extend ({
tagName: "li",
template: _.template($('#shortcakeTemplate').html()),
initialize: function(){
this.render();
},
render: function() {
var variables = { namee: name };
if (this.model.butter == false) {
this.model.deladd = "ADD";
this.model.icon= "plus";
this.el.html( template );
}
else {
this.model.deladd = "DELETE";
this.model.icon= "minus";
this.el.html( template );
}
},
)};
var ShortcakeUI = new shortcakeUI({
collection : shortcakeAlbum,
el: $("#shortcakeinterface")[0]
});
ShortcakeUI.render();
And my html is:
<ul data-role="listview" data-split-icon="gear" data-split-theme="d">
<div id="shortcakeinterface"></div>
</ul>
<!---Templates--->
<script id="shortcakeTemplate" type="text/template">
<% for(var i = 0; i < shortcakeAlbum.length; i++){ %>
<% var shortcakez = shortcakeAlbum[i]; %>
<fieldset class="ui-grid-a">
<div class="ui-block-a">
<h3><%= shortcakez.time %></h3>
<p><%= shortcakez.name %></p>
</div>
<div class="ui-block-b">
<div id="8" data-role="controlgroup" data-type="horizontal" >
<%= shortcakez.deladd %>
Test
</div>
</div>
</fieldset>
<% } %>
</script>
So with these, my UI does not show the list of models on load.
Just starting out on backbone and js, am I doing things right here?
You need to pass the model to your template in render().
Instead of
this.el.html( template );
do this
$(this.el).html( this.template(this.model.toJSON()) );

Resources