I am building a custom autocomplete field. It worked as in when I type 'a' it shows me all the list of fruits with letter 'a', but when I click on any of the options. I see the autocomplete field 'value'.   When users type a, it should show Apple, Avocado. Clicking on any of them, it should show Apple, not fruit-1 in the field.  This is the code I am using.  Form  namespace Drupal\custom_google_search\Form;  use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Routing\TrustedRedirectResponse;  class GoogleSearchAutocomplete extends FormBase {    /**    * {@inheritdoc}    */   public function getFormId() {     return 'custom_google_search_autocomplete';   }    /**    * {@inheritdoc}    */   public function buildForm(array $form, FormStateInterface $form_state) {     $form['google_places_search'] = [       '#type' =&gt; 'textfield',       '#title' =&gt; t('Searchfield'),       '#autocomplete_route_name' =&gt; 'custom_google_search.autocomplete',       '#value' =&gt; 'aaa11',     ];   $form['search_in_us'] = [     '#type' =&gt; 'submit',     '#value' =&gt; $this-&gt;t('Search'),     ];       return $form;   }    /**    * {@inheritdoc}    */   public function validateForm(array &amp;$form, FormStateInterface $form_state) {    }    /**    * {@inheritdoc}    */   public function submitForm(array &amp;$form, FormStateInterface $form_state) {    } }   Autocomplete controller  namespace Drupal\custom_google_search\Controller;  use Drupal\Core\Controller\ControllerBase; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Drupal\Component\Utility\Tags; use Drupal\Component\Utility\Unicode; use GuzzleHttp\Client; use GuzzleHttp\Exception\RequestException; use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\Core\StringTranslation\StringTranslationTrait;  class AutocompleteController extends ControllerBase {    public function handleAutocomplete(Request $request) {      // Get the typed string from the URL, if it exists.     if ($input = $request-&gt;query-&gt;get('q')) {       $typed_string = Tags::explode($input);       $typed_string = Unicode::strtolower(array_pop($typed_string));       $trimed_string = preg_replace("/\s+/", "+", $typed_string);       $results = $this-&gt;showRelatedPlaces($trimed_string);     }     return new JsonResponse($results);   }    public function showRelatedPlaces($trimed_string) {     try {        $results = [          [            'value' =&gt; 'fruit-1',            'label' =&gt; 'Apples',          ],          [            'value' =&gt; 'fruit-2',            'label' =&gt; 'Apricots',          ],          [            'value' =&gt; 'fruit-3',            'label' =&gt; 'Avocados',          ],        ];        return($results);      } catch (RequestException $e) {     return($this-&gt;t('Error occured.'));   }  }   }   Problem is that when I type a in the autocomplete textfield, it shows the fruits label (Apple), but when I click on the fruit label, the field value shows fruit-1. I want to show Apple when users select Apple.  PS: I don't want to use the same value for label and value.
123140
I have a textfield autocomplete field that shows a list of full user names and email addresses as designed but when a user is selected, the user id is displayed in the field; not the name and email address.  This is the form element:  $form['people'] = [   '#type' =&gt; 'textfield',   '#placeholder' =&gt; t('Search by name'),   '#autocomplete_route_name' =&gt; 'my_module.people', ];   This is the autocomplete handler in the controller:  public function handleAutocomplete(Request $request) {    $query = $this-&gt;database-&gt;select('simplenews_subscriber', 'ss');   $or = $query-&gt;orConditionGroup()     -&gt;condition('pa.address_given_name', '%' .$request-&gt;query-&gt;get('q') . '%', 'LIKE')     -&gt;condition('pa.address_family_name', '%' .$request-&gt;query-&gt;get('q') . '%', 'LIKE');   $query-&gt;leftJoin('simplenews_subscriber__subscriptions', 'sss', 'sss.entity_id = ss.id');   $query-&gt;leftJoin('profile', 'p', 'p.uid = ss.uid');   $query-&gt;leftJoin('profile__address', 'pa', 'pa.entity_id = p.profile_id');   $query-&gt;fields('ss', ['uid', 'mail']);   $query-&gt;fields('pa', ['address_given_name', 'address_family_name']);   $query-&gt;condition($or);   $query-&gt;orderBy('address_given_name');   $query-&gt;range(0, 10);    $results = $query-&gt;execute()-&gt;fetchAll();    $users = [];    foreach ($results as $user) {     $users[] = [       'value' =&gt; $user-&gt;uid,       'label' =&gt; $user-&gt;address_given_name . ' ' . $user-&gt;address_family_name . ' (' . $user-&gt;mail . ')',     ];   }    return new JsonResponse($users); }   The autocomplete textfield populates properly.  I just want the first name, last name and email address to show after a selection has been made.
93418
I symplified my problem: @echo off set res=  for /f &quot;usebackq&quot; %%f in (`find &quot;a&quot; list.txt`) do set res=%%f echo %res%  pause&gt;nul and that things.txt file in the code is like:  list.txt file in the code is: apple pitch pear melon mango  As you expect, the result of this code is mango  because the line 'mango' is located below the line 'apple' and 'pear' But the result I want is apple  or pear  Specifically, I want to put each of the other values above mango such as apple and pear into the variable res using option keys provided. is there any way to do that?
117127
I would like to redirect the user to a view with some contextual filters on the submit of a custom form.  For now I use this :   $form_state-&gt;setRedirect('view.search.page_1', ['myvalue' =&gt; $value]);   But it add "myvalue" like this : /search?myvalue=$value  and what I want is : /search/$value  Thanks
15484
Is it possible to automate the process of picklist values retrieval from the backend?  Here is how I am doing it right now:  @AuraEnabled public static List&lt;String&gt; retrieveMyObjectMyFieldOptions() {     List&lt;String&gt; res = new List&lt;String&gt;();      Schema.DescribeFieldResult fieldResult             = MyObject__c.MyField__c.getDescribe();     List&lt;Schema.PicklistEntry&gt; ple = fieldResult.getPicklistValues();     for(Schema.PicklistEntry f: ple) {         res.add(f.getLabel());         res.add(f.getValue());     }      return res; }   Is it possible to pass two strings to a method and get the same list as above? In other words is it possible to change the signature to the following:   public static retrieveMyObjectMyFieldOptions(String MyObject, String MyField)?
529
Im working in a site, And I need to present many fields to be filled and the page, so accoding to a selecction before, I have all the field but I have the Api Name, and the object name, but, With this api object field name, how can I get the label????  Example. I have "Student__c", I need to present "Student" to the user.  Thanks a lot for ur help!    Ok, thanks for ur answuers but I think I did not explain well this situation.   I have a list of string, where I have the information but in Api's name.  I present this fields in a table, so the user is filling the fields but with an inputText and not with an inputfield!.. So, in this moment, I dont know what is the label of each field.  My question basically, if by means of a query I could know the label of a field, if I know the api field name and the object name.. My question is if there is a way to consult this info!...  I know if I have the object is enough using an inputfield, But I cant do that. Neither set the label with HTML directly 'cause this is something dynamic.   Anyone knows how can I know, or consult, I guess by means of a query, how to get this label names???
25740
In a Lightning Component, I have the following markup which I have to comment in and out for testing purpose  &lt;force:inputField value="{!v.account.Name}" class="form-control uiInput--input input" /&gt;   now when I try to comment it out like this  &lt;!--&lt;force:inputField value="{!v.account.Name}" class="form-control uiInput--input input" /&gt;--&gt;   the API tells me     markup://c:elfL1:6,81: ParseError at [row,col]:[7,81] Message: The   string "--" is not permitted within comments.   Since I didn't figure out that fancy class name uiInput--input (Salesforce did so...) it would be nice to be able to toggle that om/off OR avoid to use class names like this...
120765
I would like to be able to selectively edit specific auto-fill form values in Safari - rather than just delete the entire form data for that site.  I know I can do the latter from Prefs > AutoFill > other forms > Edit… but I'd rather be able to remove only the the oddities my errant typing appears to have generated, rather than the actually useful auto-fills I already have in there.  As an example, from the Edit panel in Ask Different itself, I appear to have several aborted versions of "Formatting". I would rather have just the 'correct' entries.     A guess would be that the data resides in ~/Library/Safari/Form Values but that file seems to be either encrypted or perhaps binary - I can't tell which.  OS X 10.10.4 Safari 8.0.7
31957
When validating a field manually from my form a error is displayed but the field doesn't get red. For the first parameter i used the name of the input element. DRUPAL 7  if($form_state['values']['panes']['webform_nid31'][0]['contact_person'] == '') {     form_set_error('panes[webform_nid31][0][contact_person]', t('You must select a name for this group of settings.'));   }
10893
I have 3 different custom fields url-1, url-2 and url-3. Each field have different value in type of &lt;iframe&gt; embedded video.     Click any link &lt;li&gt; and play that video, By default play url-1   HTML:  &lt;form  id="myform"&gt;    &lt;li&gt;&lt;a name="url-1" class="play_next" href="#"&gt; Link &lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a name="url-2" class="play_next" href="#"&gt; Link &lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a name="url-3" class="play_next" href="#"&gt; Link &lt;/a&gt;&lt;/li&gt; &lt;/form&gt;  &lt;div id="output"&gt; video player &lt;/div&gt;   Jquery  jQuery(document).ready(function($){ $("#myform").on('click', 'a', function(e) {  $.ajax({     url: ajaxobject.ajaxurl,     type: 'post',     data: {          action: 'call_meta',      },     success: function(result) {         $('#output').append( result );     } }); }); });   PHP:  add_action('wp_ajax_call_post', 'call_meta'); add_action('wp_ajax_nopriv_call_post', 'call_meta');  function call_meta(){  if( isset($_POST["pid"]){    $post = get_post( $_POST["pid"] );      echo get_post_meta( $ID, 'url-1', true ); }  else {     echo get_post_meta( $ID, 'url-2', true ); } else {     echo get_post_meta( $ID, 'url-3', true ); } wp_die(); }   How to load video with Ajax? &amp; play any from others by replacing previous one.  I'm new in wordpress theme development, So I know that there is many problem and error in my code. Thanks for your attention. I’m looking forward to your reply.
76601
When the standard Name field of an object is set as Text, it shows a weird behavior if left empty. It is not possible to mark it as required or non-required, but when editing a record from its standard edit page, the field is required:    No problem so far: the field is required in any case. The problem arises when it comes to insertion from code. If we insert a record from code:  CustomObject__c r = new CustomObject__c(); insert r;   ... we get no error. Instead, the record is inserted with the short, 15-character Id copied into its Name field. What I would expect is an exception with the same error that we've got in the standard edit page.  This problem does not occur with custom fields: if a custom field is marked as required, it will be so both in the standard edit page and from code.  I did not find any mention to this on documentation. Is this behavior new in Spring'14? Has any of you found this same problem before?
91776
I have created a shortcode that retrives and displays a form.The content of the attribute in HTML.   function check_my_login( $atts)     {          return '&lt;form action="" name="" method="post" enctype="multipart/form-data"&gt;                &lt;div class="form-group"&gt;                     &lt;label for="description"&gt;Project Description&lt;/label&gt;                     &lt;textarea name="p_description" placeholder="Project Description" class="form-control"&gt;&lt;?php if (isset($_POST['p_description']) &amp;&amp; $_POST['p_description'] != '') echo $_POST['p_description'] ?&gt;&lt;/textarea&gt;                 &lt;/div&gt;                  &lt;div class="form-group"&gt;                     &lt;label&gt;Project Attachment&lt;/label&gt;                     &lt;input type="file" name="p_attachment"&gt;                 &lt;/div&gt; &lt;/form&gt;';     }     add_shortcode( 'kentaUser', 'check_my_login' );   Now use this shortcode inside the Post/page.   Like this    &lt;div class='manage_page'&gt;[kentaUser]&lt;/div&gt;  But my shortcode content display out side the div.Display upper side in post/page content.  &lt;div class='manage_page'&gt;&lt;/div&gt;    Any one short out this problem.
42855
I want to search for what += means, but Google won't return any documents.  Also when I come across some PHP code I don't understand I can't search for the keywords as written.  How can I search for these special characters or include these special characters in a search.
10807
maybe there is a simple answer to my problem:  I have a mssql table ('Person') with a field for first and one for last name. I am coding a Program, where the User should be able to search for persons.     SELECT id, firstname, lastname FROM Person WHERE firstname LIKE   @searchstring + '%' OR lastname LIKE @searchstring + '%'   doesn't work very well, because if the user types 'John W' nothing is found.  For example the person I search for is called John Williams: It should work with searchstrings like 'John W', 'Williams Jo', 'Will' or 'Joh'  Concatenating first and lastname and use %Searchstring% also doesn't work well, because if the searchstring is e.g. 'Will' it should find people who are called Will, Willibald, Williams or Willson or something like that, but not a Person called Goodwill e.g.  And the query should be as fast as possible, because it is executed at every keydown...  edit: forgot to mention that the database must not be changed, because it is from another company.  Thank you for your help.
80030
I'm working on a project in which I'm creating a custom post type and custom data entered via meta boxes associated with my custom post type. For whatever reason I decided to code the meta boxes in such a way that the inputs in each metabox are part of an array. For instance, I'm storing longitude and latitude:  &lt;p&gt;      &lt;label for="latitude"&gt;Latitude:&lt;/label&gt;&lt;br /&gt;      &lt;input type="text" id="latitude" name="coordinates[latitude]" class="full-width" value="" /&gt;  &lt;/p&gt;  &lt;p&gt;          &lt;label for="longitude"&gt;Longitude:&lt;/label&gt;&lt;br /&gt;      &lt;input type="text" id="longitude" name="coordinates[longitude]" class="full-width" value="" /&gt;  &lt;/p&gt;   For whatever reason, I liked the idea of having a singular postmeta entry for each metabox. On the save_post hook, I save the data like so:  update_post_meta($post_id, '_coordinates', $_POST['coordinates']);   I did this because I have three metaboxes and I like just having 3 postmeta values for each post; however, I've now realized a potential issue with this. I may want to use WP_Query to only pull out certain posts based these meta values. For instance, I may want to get all posts that have latitude values above 50. If I had this data in the database individually, perhaps using the key latitude, I would do something like:  $args = array(     'post_type' =&gt; 'my-post-type',     'meta_query' =&gt; array(         array(             'key' =&gt; 'latitude',             'value' =&gt; '50',             'compare' =&gt; '&gt;'         )     )  ); $query = new WP_Query( $args );   Since I have the latitude as part of the _coordinates postmeta, this would not work.  So, my question is, is there a way to utilize meta_query to query a serialized array like I have in this scenario?
31321
I have a requirement to translate few predetermined spanish characters to english in field values of different custom objects. I have tried to create a generic code. can someone please let me know where it fails to give desired output?  Apex class snippet:  public static String translate(String str) {   M= new Map&lt;String,String&gt;{'á'=&gt;'a', 'é'=&gt;'e' ,'í'=&gt;'i', 'ó'=&gt;'o', 'ú'=&gt;'u', 'ü'=&gt;'u', 'ñ'=&gt;'n'};    for (String key: M.keyset())//iterate over keyset   {     str.replace(key,M.get(key));//Get CORR Value   }    return str;//english }
20612
I have a picklist field-XYZ which contains a lot of values.Lets say (A,b,c,d...z) I am trying to write a rule criteria which will execute if the picklist value is any of the following (A,b,c...p).So instead of mentioning all the values in rule criteria , i created a custom label and put the values (a,b,c,d..p) in that and wrote the following in the rule criteria :   CONTAINS(TEXT(XYZ__c) ,$Label.CustomLabel))   This is not working even is the value of the picklist is equal to the one mentioned in the Custom Label.I guess the CONTAINS function is matching the whole value of custom label with Picklist.Is there other workaround/solution for this?
89673
I am trying to get  to work within salesforce visualforce pages.  I have a basic vf page from  example, but it does not respopnd, I suspect there may be some "unknown" workaround needed? Does anyone know?  &lt;apex:page standardController="Contact" showHeader="false" sidebar="false" docType="html-5.0"  standardStylesheets="false"&gt;  &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"&gt;&lt;/script&gt; &lt;script src="http://twitter.github.io/typeahead.js/releases/latest/typeahead.bundle.js"&gt;&lt;/script&gt;      &lt;div id="the-basics"&gt;   &lt;input class="typeahead" type="text" placeholder="States of USA"/&gt; &lt;/div&gt;  &lt;script&gt;     var substringMatcher = function(strs) {       return function findMatches(q, cb) {         var matches, substrRegex;          // an array that will be populated with substring matches         matches = [];          // regex used to determine if a string contains the substring `q`         substrRegex = new RegExp(q, 'i');          // iterate through the pool of strings and for any string that         // contains the substring `q`, add it to the `matches` array         $.each(strs, function(i, str) {           if (substrRegex.test(str)) {             // the typeahead jQuery plugin expects suggestions to a             // JavaScript object, refer to typeahead docs for more info             matches.push({ value: str });           }         });          cb(matches);       };     };      var states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California',       'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii',       'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana',       'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota',       'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire',       'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota',       'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island',       'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont',       'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'     ];      $('#the-basics .typeahead').typeahead({       hint: true,       highlight: true,       minLength: 1     },     {       name: 'states',       displayKey: 'value',       source: substringMatcher(states)     }); &lt;/script&gt;