In my database I store money as an integer, similar to Stripe. For instance 12.99 is stored as 1299. Basically taking the number and dividing by 100.
I'm trying to incorporate this with Yii2 activeForm, specifically using either the MaskInput or MaskMoney widgets. However, I cannot figure out how to configure either widget so that when the value is "1299" it displays as "12.99". So if a person types in "1200" it displays as "12.00".
This is for a simple frontend solution and not backend so I'm not looking for Yii scenarios or behaviors in this question.
I'm not sure if I understood correctly, but this is the closest I've ever got to what you want.
<?php echo \yii\widgets\MaskedInput::widget([
'name' => 'masked-input',
'clientOptions' => [
'alias' => 'decimal',
'digits' => 2,
'digitsOptional' => false,
'radixPoint' => '.',
'groupSeparator' => ',',
'autoGroup' => true,
'removeMaskOnSubmit' => true,
],
]); ?>
The behaviour of the decimal part is what bothers me, but it works as intended.
Related
I am pretty much below beginner level for REGEX/REGEXP and have hit a blocking point in a project I am working in, where I am trying to get the ids for posts that match the search criteria , but I want to restrict the search between 2 sub-strings. I am trying to figure out is how to write the REGEXP in the meta_query:
$args = array(
'post_type'=> 'custom',
'order' => 'DESC',
'posts_per_page' => 10,
'paged' => $page,
'meta_query' => array(
array(
'key' => 'key',
'value' => "title*".$search."*_title",
'compare' => 'REGEXP',
)
),
);
And an example of the field in the DB :
a:302:{s:5:"title";s:10:"Test title";s:6:"_title";s:19:"
Unfortunately none of the combinations I tried based on documentation of SQL REGEXP won't return any values and I am trying to understand how I can pull this off and would appreciate any input.
Also would rather stick to WP_Query for now even though an SQL LIKE "%title%{$search}%_title%" works perfectly , so an alternative solution would be how to set the compare to 'LIKE' and parse it '%' since that is not possible out of the box as the % get escaped I believe.
I'm still new to the ElasticSearch technology and right now struggle with creating index template that will be applied to all new indices but can't create proper one.
Currently running ElasticSearch 7.9.2 and it's documentation index templates informs that index_patterns field is required and should be array of wildcards (* matches any string).
Naturally I have tried using ["*"] as pattern via Kibana's console for request:
PUT _index_template/template_1
{
"index_patterns": ["*"],
"priority": 0
}
I've got:
{
"error" : {
"root_cause" : [
{
"type" : "null_pointer_exception",
"reason" : null
}
],
"type" : "null_pointer_exception",
"reason" : null
},
"status" : 500
}
while for request that added empty settings:
PUT _index_template/template_1
{
"index_patterns": ["*"],
"template": {
"settings": {
}
},
"priority": 0
}
I've received:
#! Deprecation: index template [template_1] has index patterns [*] matching patterns from existing older templates [.monitoring-es,.triggered_watches,.management-beats,.transform-internal-005,.logstash-management,.monitoring-kibana,.kibana-event-log-7.9.2-template,.ml-config,.watch-history-11,.ml-meta,ilm-history,.monitoring-logstash,.ml-state,.slm-history,.ml-inference-000002,.monitoring-beats,.monitoring-alerts-7,.ml-anomalies-,.watches,.ml-notifications-000001,.transform-notifications-000002,.ml-stats] with patterns (.monitoring-es => [.monitoring-es-7-*],.triggered_watches => [.triggered_watches*],.management-beats => [.management-beats],.transform-internal-005 => [.transform-internal-005],.logstash-management => [.logstash],.monitoring-kibana => [.monitoring-kibana-7-*],.kibana-event-log-7.9.2-template => [.kibana-event-log-7.9.2-*],.ml-config => [.ml-config],.watch-history-11 => [.watcher-history-11*],.ml-meta => [.ml-meta],ilm-history => [ilm-history-2*],.monitoring-logstash => [.monitoring-logstash-7-*],.ml-state => [.ml-state*],.slm-history => [.slm-history-2*],.ml-inference-000002 => [.ml-inference-000002],.monitoring-beats => [.monitoring-beats-7-*],.monitoring-alerts-7 => [.monitoring-alerts-7],.ml-anomalies- => [.ml-anomalies-*],.watches => [.watches*],.ml-notifications-000001 => [.ml-notifications-000001],.transform-notifications-000002 => [.transform-notifications-*],.ml-stats => [.ml-stats-*]); this template [template_1] will take precedence during new index creation
{
"acknowledged" : true
}
Response depends only on existence of empty template.settings it seems like it might be slightly bugged.
Nevertheless latter approach seems to work however deprecation warning sounds dangerous and discouraging (I've tried setting priority to 0 but to no avail). However Documentation of 6.8 version sports example of "*". So such functionality existed not long ago.
What is the proper way, if there is one, to construct "match all" index template?
Currently to match all indices you really need to use the * as the index pattern and the warning is there because it will match anything, including the internal systems indices.
Depending on what is in your template this can lead to things not working right or break your system.
There is an open issue on github about it, mostly regarding to the .security index, which is also affected when you use an match all index pattern, and there is another open issue that also deals with this problem.
I'm trying to create an ad using the php sdk.
I can create the campaign, targeting, adset, and the creative (which returns a creative_id that I can validate using the graph explorer).
But when I finally run the code to create the ad itself, I get an exception that looks like this:
"error_user_title" => "Missing creative spec"
"error_user_msg" => "No creative spec found for given adgroup."
I just can't find anything referring to this error.
Below is the relevant portion of my code:
$link_data = new AdCreativeLinkData();
$link_data->setData(array(
AdCreativeLinkDataFields::LINK => $route,
AdCreativeLinkDataFields::MESSAGE => $petition_statement,
AdCreativeLinkDataFields::NAME => $banner_title,
AdCreativeLinkDataFields::IMAGE_HASH => $image_hash,
));
$object_story_spec = new AdCreativeObjectStorySpec();
$object_story_spec->setData(array(
AdCreativeObjectStorySpecFields::PAGE_ID => $pageid,
AdCreativeObjectStorySpecFields::INSTAGRAM_ACTOR_ID=>$instagram_id,
AdCreativeObjectStorySpecFields::LINK_DATA=>$link_data
));
$creative = new AdCreative(null,$account_id);
$creative->setData(array(
AdCreativeFields::TITLE => $banner_title,
AdCreativeFields::BODY => $banner_subtitle,
AdCreativeFields::IMAGE_HASH => $image_hash,
AdCreativeFields::OBJECT_TYPE => 'SHARE',
AdCreativeFields::OBJECT_STORY_SPEC=>$object_story_spec
));
$creative->create();
echo 'Creative ID: '.$creative->id . "\n";
$ad = new Ad(null, $account_id);
$ad->setData(array(
AdFields::NAME => $short_name,
AdFields::ADSET_ID => $adset->id,
AdFields::CREATIVE => $creative,
AdFields::TRACKING_SPECS => array(array(
'action.type' => 'offsite_conversion',
'fb_pixel' => $pixel_code,
))
));
$ad->create(array(Ad::STATUS_PARAM_NAME => Ad::STATUS_PAUSED));
Appreciate any help.
I've often said that the only skill you need to be a successful developer is the ability to agonize over a problem for days, read through source code, google it, refactor, rewrite and then realize you forgot something fucking obvious.
AdFields::CREATIVE => $creative,
should read
AdFields::CREATIVE => $creative->id,
But the ability to persist isn't the skill you need. The real skill is to somehow resist the overwhelming urge to chuck your computer out the window and do something productive with your life instead.
After hours of testing it seems Trevor's answer is incorrect. This is the right syntax:
AdFields::CREATIVE => array('creative_id'=>$creative->id)
We have a hybrid app built using Cordova and it has a login user and password field. The applicatio is developed based on EmberJs stack. We are using Calabash 1.* version and other components works fine except all text boxes.
I am able to successfully query the input elements using the below code in console.
query("systemWebview css:'input'")
I get the below query result in console. But text value is always empty even if I enter some value.
{
"class" => "ember-view ember-text-field",
"nodeType" => "ELEMENT_NODE",
"id" => "ember555",
"textContent" => "",
"html" => "<input id=\"ember555\" class=\"ember-view ember-tex
ld\" placeholder=\"Enter User name\" type=\"text\">",
"rect" => {
"y" => 202,
"x" => 0,
"center_x" => 360,
"height" => 74,
"width" => 720,
"top" => 76,
"left" => 0,
"center_y" => 238
},
"nodeName" => "INPUT",
"webView" => "NoResourceEntry-100"
},
In the Ruby section, I have the below code and it also returns empty value.
query(objectName, :textContent).first
Any help is appreciated. Thanks in advance.
Code
query "UIWebView", :calabashStringByEvaluatingJavaScript => "document.querySelectorAll('input#ember555')[0].value"
Explanation
Breaking it down,
1.
query "UIWebView",
Gets the webview.
2.
:calabashStringByEvaluatingJavaScript => ...
This is a selector which calabash-ios-server adds to webviews such that any webview (UIWebView or WKWebView) should respond to it. The selector is invoked on the result of query "UIWebView"
3.
"document.querySelectorAll('input#ember555')[0].value"
This is a standard javascript selector that you can tweak as necessary to get your element. E.g., you could use document.getElementById() or whatever is most convenient. This string of javascript is used as an argument to the calabashStringByEvaluatingJavaScript selector.
I realize it would be nice to have the text just returned as part of the object, I'll check with the team and see if we should file an issue (or, feel free to file one yourself at https://github.com/calabash/calabash-ios-server/issues ).
Thanks to #christoper, I found some working solution for android.
evaluate_javascript("systemWebView", "return document.getElementById('nicknameid').value;")
The same logic works for checkbox validation too.
I am creating google charts to show Google Analytics data from the past 7 days. I have an issue with the X-Axis labels stacking on top of each other when I have certain data (or at least that's all I can tell is different.)
I am generating the API call using this gem: https://github.com/mattetti/googlecharts and I've looked at what each part of the URL is doing and can't find the issue, but I'm sure I'm missing something.
Here is an example of two sites data over the same time period, the first one shows the issue and the second one is a working example:
Here is the URL, these are text encoded for readability, but it has the same issues when switched to simple or extended encoding:
BROKEN VERSION:
https://chart.apis.google.com/chart?chxl=0:|11-22|11-23|11-24|11-25|11-26|11-27&chxt=x&chco=58838C,BF996B,BF5841,A61C1C&chf=bg,s,ffffff&chd=t:979,807,681,653,580,509|822,724,602,562,519,455|540,409,381,375,336,301|307,156,173,176,155,133&chds=0,979&chdl=Visits|Visitors|New+Visits|Organic+Searches&chtt=Google+Analytics+-+Last+7+Days&cht=lc&chs=600x200&chxr=0,979,979|1,822,822|2,540,540|3,307,307
WORKING VERSION:
https://chart.apis.google.com/chart?chxl=0:|11-22|11-23|11-24|11-25|11-26|11-27&chxt=x&chco=58838C,BF996B,BF5841,A61C1C&chf=bg,s,ffffff&chd=t:1385,1395,981,947,863,731|1083,1222,832,715,690,546|580,566,427,413,387,329|247,151,151,171,162,135&chds=0,1395&chdl=Visits|Visitors|New+Visits|Organic+Searches&chtt=Google+Analytics+-+Last+7+Days&cht=lc&chs=600x200&chxr=0,1385,1395|1,1083,1222|2,580,580|3,247,247
The chxr values were incorrect. The gem was generating them for multiple axes when it should have only been generating them for one. I manually overrode the min, max and step in the gem and it worked.
Here is my code using the gem, first getting the max value from all my data points:
[#visits,#visitors,#new_visits,#organic_searches].each do |array|
array.values.each do |value|
#max_value = value if (value > #max_value)
end
end
# Chart it
chart = Gchart.line(
:title => prop.to_s.upcase + ' Google Analytics - Past 7 Days',
:size => '600x200',
:bg => 'ffffff',
:axis_with_labels => ['x'],
:axis_labels => [#visits.keys],
:legend => ['Visits','Visitors','New Visits','Organic Searches'],
:line_colors => ['58838C','BF996B','BF5841','A61C1C'],
:encoding => 'text',
:data => [#visits.values,#visitors.values, #new_visits.values, #organic_searches.values],
:max_value => #max_value,
:axis_range => [nil, [0, #max_value, (#max_value / 10).to_i]],
:format => 'image_tag')