Weird behaviour with Select.Async and loadOptions - react-select

I have a question about react-select component.
I have following code (coffeescript) and very weird behaviour (on the gif below). The question is -- waht I'm doing wrong? Why options not shown immediately after the getOptions func done? Why they shown only after the click outside? That's super confusing.. I need your help guys!
getOptions = (value) =>
return Promise.resolve({options: []}) unless value
api.geocoder(value).then (data) =>
countries = [
{value: 'A', label: 'A'}
{value: 'B', label: 'B'}
]
console.info(countries)
{options: countries}
<Select.Async
className="ads-filter__select"
value={#props.country_code}
onChange={(option) => #props.onChange('country_code', option)}
clearable={false}
placeholder={I18n.t('ads.country')}
loadOptions={getOptions}
/>

Add this property to Select.Async: filterOption={() => (true)}
To be more specific write:
<Select.Async
className="ads-filter__select"
value={#props.country_code}
filterOption={() => (true)}
onChange={(option) => #props.onChange('country_code', option)}
clearable={false}
placeholder={I18n.t('ads.country')}
loadOptions={getOptions}
/>
Hope this will solve your issue

Related

How create a new line with table.create

I have one problem with RubyonRails.
I created a BDD with a table Article.
For add some line on this table, I do :
hello = Article.new(:title => title, :content => content)
hello.save
But I know another method exists with "table.create title: 'title'"
But it didn't work with more than one column.
Can someone tell me how I can do thing like :
article.create = title: 'title', content: 'content'

yii2 response formatter not being called

I'm trying to use robregonm pdfresponseFormatter to create a PDF, problem is, the pdf class is never called as the format reponse type.
'response' => [
'formatters' => [
'html' => [
'class' => 'yii\web\HtmlResponseFormatter',
],
'pdf' => [
'class' => 'robregonm\pdf\PdfResponseFormatter',
'mode' => '',
'format' => 'A4',
'defaultFontSize' => 0,
'defaultFont' => '',
'marginLeft' => 15,
'marginRight' => 15,
'marginTop' => 16,
'marginBottom' => 16,
'marginHeader' => 9,
'marginFooter' => 9,
]
]
],
....
$file = $this->getPdf($report);
....
private function getPdf($report){
Yii::$app->response->format = 'pdf';
Yii::$container->set(Yii::$app->response->formatters['pdf']['class']);
$this->layout = '//attachment';
return $this->render('pdf/actionplan', ['model' => $report]);
}
the $file variable has the HTML text in it from the view
You are asking the wrong question. Of course $file has HTML in it, you are returning HTML from your view.
Yii::$app->response->format = 'pdf';
works when the controller returns a response to the browser.
What you want to ask is why the controller function (I hope this is in a controller) does not return a PDF created from the HTML.
If you just want to save a PDF look how I handle this: https://github.com/Mihai-P/yii2-core/blob/master/components/Controller.php in the actionPdf function. That function returns a file that you can save on the server if you want.
Unfortunately I've not been able to get this extension to work. I did get kartik pdf to work great
I recommend using the kartik extension instead.

Ruby integration with mailchimp-api gem

I'm trying to subscribe a single email to multiple lists with RoR and the official mailchimp-api gem. It works, but the last four values (double_optin, update_existing, replace_interests, and send_welcome) are not updating and I get an error that the email "already exists" even though I'm trying to pass the update_existing as true. I've written Mailchimp several times and they feel they've reached the end of their assistance. They have said they are not experts in the wrapper--even if it is the "official" gem--and cannot help me further. My code looks like this:
responses << mailchimp_lists.each do |ml|
mailchimp.lists.subscribe(
ml,
{ "email" => order.customer_email,
"euid" => order.customer_id,
"leid" => ""
},
{ "FNAME" => order.customer_first_name,
"LNAME" => order.customer_last_name,
"COMPANY" => order.company_name,
"ADDRESS1" => order.billing_address_1,
"ADDRESS2" => order.billing_address_2,
"CITY" => order.billing_city,
"STATE" => order.billing_state,
"POSTALCODE" => order.billing_zip,
"SALUTATION" => ""
},
"html",
false,
true,
false,
false
)
end
I've tried sending the last four params in several different ways such as:
"email_type" => "html",
"double_optin" => false,
Or:
{"email_type" => "html"},
{"double_optin" => false}
At times, Mailchimp can see the params arrive in such a way that it seems it should not be triggering an "email already exists" error, but it just won't work. Any help is appreciated.
The mailchimp-api gem's documentation describes the subscribe method as:
#subscribe(id, email, merge_vars = nil, email_type = 'html', double_optin = true, update_existing = false, replace_interests = true, send_welcome = false)
While the batch_subscribe shows:
#batch_subscribe(id, batch, double_optin = true, update_existing = false, replace_interests = true)
Note that the batch method does not include a "send_welcome" param. When I removed it from my list of params for the subscribe method--essentially sending three booleans instead of four as suggested, the update_existing worked perfectly. Seems like an error in the documentation here: http://www.rubydoc.info/gems/mailchimp-api/2.0.4/Mailchimp/Lists#subscribe-instance_method
Hopefully this helps someone else!

rails 3.2 jquery autocomplete minlength

I am following the instructions to implement auto complete in a rails 3.2.11 application but I need to specify a minimum number of characters to type before the query triggers. THe jQuery API documentation has an attribute "minLength". I can't figure out how to implement this in a rails auto complete field tag. Here is my code for the field tag.
<%= autocomplete_field_tag 'unit', '', autocomplete_unit_identifier_subjects_path, :id_element => '#subject_id', :size => 75 %>
Here is the url to the instructions I am following.
https://github.com/crowdint/rails3-jquery-autocomplete
If anyone is looking for an updated answer, it appears you can now set minimum length with the attribute 'min-length'.
<%= autocomplete_field_tag 'group_name', '', group_autocomplete_path, 'placeholder' => 'Select a Job Number', 'size' => 35, 'class' => 'styled-select', 'data-auto-focus' => true, 'min-length' => 1 %>
Why its not 'minlength' as documented in jQuery autocomplete, I don't know..
Well, minLength doesn't work because of this code in autocomplete-rails.js, line 65 or so:
search: function() {
// custom minLength
var term = extractLast( this.value );
if ( term.length < 2 ) {
return false;
}
},
You can change the '2' to whatever you want the minLength to be.

LookbackAPI: When did user stories become unblocked?

I'm running the following query to the lookback API to find stories in a date range that were unblocked, but I'm getting no results. Am I missing something obvious? No errors, warnings or results returned.
Below is the Generated Query I get back from the lookback API:
'GeneratedQuery' => {
'fields' => 'true',
'skip' => 0,
'limit' => 100,
'find' => {
'_PreviousValues.Blocked' => 'true',
'_TypeHierarchy' => -51038,
'Blocked' => 'false',
'_ValidFrom' => {
'$lte' => '2012-11-02T04:00:00.000Z',
'$gte' => '2012-07-01T04:00:00.000Z'
}
}
},
When you pass in Boolean values, you need to make sure that they are bare true or false. If you pass them in as Strings, it will not behave as expected. Similarly for values of type Number. They should not have quotes around them.
Ok, the problem was related to "true" and "false" and the fact that I'm using Perl.
I'm using the Perl JSON library, and I didn't realize that you need to pass in JSON::true() and JSON::false() for true and false, not the literals 'true' and 'false'. So, in effect Larry was right: it was passing "true" instead of true.