populating a custom field automatically..
Posted: 13 January 2011 10:16 PM   [ Ignore ]
Wallflower
Rank
Total Posts:  11
Joined  2010-12-23

Hi Rob,
Why is the following code is not working??
I am trying to populate this field automatically by the title value of an entry from another channel “apartment”. The title value selection is based on the url_title found in segment 3 in this new entry being added…
I hope I made self clear..

<fieldset>
      <label for=“apt_id_rent1” id=“apt_id_rent1_lbl”>عÙ?Ù?اÙ? اÙ?Ø´Ù?Ø©</label>
      <input type=“text” name=“apt_id_rent1” id=“apt_id_rent1” value=”{exp:channel:entries channel="apartment" url_title="{segment_3}”}
                         
                          {title} {/exp:channel:entries}”  size=“25” maxlength=“25” />
      </fieldset>

Thanks for your support..

Profile
 
 
Posted: 13 January 2011 10:27 PM   [ Ignore ]   [ # 1 ]
Wallflower
Rank
Total Posts:  11
Joined  2010-12-23

May be it is important to give you an idea of what I am trying to do..
I am trying to select a value (title) from a relationship custom field. this selection should take place automatically away from the user eyes and it should be based on segment 3 in this template which (at the same time) is the corresponding url_title of that title (the options found in that relationship field)...

I have experimented using another custom field:

<fieldset>
      <label for=“apt_id_rent” id=“apt_id_rent_lbl”>عÙ?Ù?اÙ? اÙ?Ø´Ù?Ø©</label>
      {field:apt_id_rent}
      </fieldset>

but this is only showing me the options without being able to automatically select a value


Thanks again

Profile
 
 
Posted: 13 January 2011 10:34 PM   [ Ignore ]   [ # 2 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

Is it just coming up blank? Try:

{exp:channel:entries channel="apartment" url_title="{segment_3}" dynamic="no"}
<input type="text" name="apt_id_rent1" id="apt_id_rent1" value="{title}" />
{/exp:channel:entries} 

It may also be a parse order issue, in which case you could do something like this:

{exp:query sql="SELECT title AS apartment_title FROM exp_channel_titles WHERE url_title = '{segment_3}'"}
<input type="text" name="apt_id_rent1" id="apt_id_rent1" value="{apartment_title}" />
{/exp:query} 
Profile
 
 
Posted: 14 January 2011 11:31 PM   [ Ignore ]   [ # 3 ]
Wallflower
Rank
Total Posts:  11
Joined  2010-12-23

Hi Rob,
Thanks for posting…

well only the second code chunk worked well but it didn’t solve my problem…

I really need to use my relationship custom field tag not the input tag. Remember I need to auto select an option from my relationship field (the selection has to be the title field corresponding to Segment_3 )

But I can’t do anything right now with Safe cracker’s relationship single variable tag…Do you have a clue for that???

Regards

Profile
 
 
Posted: 14 January 2011 11:32 PM   [ Ignore ]   [ # 4 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

So you still want a select field to show? And you just want to auto select a certain option in that select?

Profile
 
 
Posted: 15 January 2011 12:00 AM   [ Ignore ]   [ # 5 ]
Wallflower
Rank
Total Posts:  11
Joined  2010-12-23

Yes pleasssee…

Profile
 
 
Posted: 15 January 2011 12:18 AM   [ Ignore ]   [ # 6 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29
<fieldset>
      <
label for="apt_id_rent" id="apt_id_rent_lbl">عÙ?Ù?اÙاÙ?Ø´Ù?Ø©</label>
      
{field:apt_id_rent}
</fieldset>

{exp:query sql="SELECT entry_id AS apartment_entry_id FROM exp_channel_titles WHERE url_title = '{segment_3}'"}
script type="text/javascript" >
$(
'select[name=apt_id_rent]').val('{apartment_entry_id}');
< /
script >
{/exp:query} 
Profile
 
 
Posted: 15 January 2011 06:01 AM   [ Ignore ]   [ # 7 ]
Wallflower
Rank
Total Posts:  11
Joined  2010-12-23

Hi Bob,
The script just worked perfect. I can’t thank you enough..
I really have so little knowledge of JavaScript, but I know it was doable with JavaScript.

I think what we can have as an alternative way is to make the relationship custom field a pair tag, then we can easily select the matching option. I hope you could consider this feature request in the future…

Thank you for the great support so far..

Profile