1

I have a channel for events, which includes the time, date and city that the event is in. In approximately 80% of cases, the event's city will be Sydney.

Is it possible for me to define Sydney as the default value so that it's pre-filled when a user creates a new entry? I'm sure there's a relatively easy way to do this using a fieldtype or extension, however I would prefer to have this functionality natively.

Also, I guess you could do this on templates, using code such as:

{exp:channel:entries channel="events" dynamic="no"}
  {if city}
    {city}
  {if:else}
    Sydney
  {/if}
{/exp:channel:entries}

but then I would have to remember to do this for every template that it occurs on, which is not ideal.

Cheers, for any help

3

Not natively but you could throw a little JS into the field instructions as per this question.

<script>
  $(function(){
    if (document.location.href.indexOf("entry_id") == -1) { // if it's a new entry
      var field = $("#field_id_15");
      if (field.val() == "") { field.val("Sydney"); }
    }
  });
</script>

Obviously just replace that with the appropriate ID of your field.

1

What kind of fieldtype are using for cities? If it is a select fieldtype, you just need to put Sydney at the top of all options.

1
  • Good suggestion, cheers, though in this case I'd rather the user be able to enter any city he/she would like, rather than just choose from a set selection of cities – David Leitch Sep 2 '13 at 8:27
0

If the fieldtype for city is simply a text field, one option would be to split it in two and use the awesome entry type add-on to hide a custom field for an "other" city assignment. So in the entry type field, you would have two values - "Sydney" and "Other". When Other is selected, a new text field would appear that would accept the other city value as a text field. Or at least that's how you CAN set it up. Then you would have a conditional very similar to what you're looking for. Something like:

{exp:channel:entries channel="events" dynamic="no"}
  {if city == "Other"}
    {other_city}
  {if:else}
    {city}
  {/if}
{/exp:channel:entries}

Wherein the default value of {city} would be "Sydney", and {other_city} would come into play only if the value of {city} was selected to be "Other". The entry type field can be radio button or dropdown list - and so dropdown list, with Sydney as the first option, would be a simple way to achieve what you're looking to do - and have it be quite user friendly to the site admins.

Hope that helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.