function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
DannyK89DannyK89 

JavaScript and Repeat

I am having some issues that I need some help with.

 

I have a page with a field set on it that is part of a repeat tag. I want the look up field to auto populate with the users first and last name. I have found a way to populate the look up but it can't be part of the repeat tag. I am not sure what the problem is. 

 

Visualforce code:

 

<apex:page standardController="Account" showHeader="false">
 <script type="text/javascript" charset="utf-8" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>  
 <script type="text/javascript" charset="utf-8" src="http://code.jquery.com/mobile/1.0b3/jquery.mobile-1.0b3.min.js"></script>
  <apex:form id="AccountForm">
      <apex:pageBlock id="AccountBlock">
      <apex:pageBlockSection id="AccountSection">
          <apex:inputField id="Contact" value="{!Account.Contact_Test__c}" rendered="true"/>
          <apex:repeat id="FieldList" value="{!$ObjectType.Account.FieldSets.test}" var="set">
              <apex:inputField id="ContactLookup" value="{!Account[set]}" rendered="{!CONTAINS(LOWER(set), LOWER('Contact_Test__c'))}"/>
              <apex:inputField value="{!Account[set]}" rendered="{!NOT(CONTAINS(LOWER(set), LOWER('Contact_Test__c')))}"/>
          </apex:repeat>
      </apex:pageBlockSection>
      </apex:pageBlock>
  </apex:form>
<script type="text/javascript">
  try
  {
    var form = document.getElementsByTagName("FORM");
    var formid= '#' + form[0].id.replace(/:/g, "\\:");
    $(formid+"\\:AccountBlock\\:AccountSection\\:Contact").val('{!$User.FirstName} {!$User.LastName}');
  }
  catch(err)
  {
    alert(err);
  }
</script>
</apex:page>

 

Navatar_DbSupNavatar_DbSup

Hi,

 

I have tried your code, use two alerts in the JavaScript. Your JavaScript executes with repeat correctly. But, you use $User.FirstName and $User.LastName which always returns the current user name.

 

<apex:page standardController="Account" showHeader="false">
<script type="text/javascript" charset="utf-8" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript" charset="utf-8" src="http://code.jquery.com/mobile/1.0b3/jquery.mobile-1.0b3.min.js"></script>
<apex:form id="AccountForm">
<apex:pageBlock id="AccountBlock">
<apex:pageBlockSection id="AccountSection">
<apex:inputField id="Contact" value="{!Account.Contact_Test__c}" rendered="true"/>
<apex:repeat id="FieldList" value="{!$ObjectType.Account.FieldSets.AccountsAndContactsEdit}" var="set">
<apex:inputField id="ContactLookup" value="{!Account[set]}" rendered="{!CONTAINS(LOWER(set), LOWER('Contact_Test__c'))}" />
<!-- <apex:inputField value="{!Account[set]}" rendered="{!NOT(CONTAINS(LOWER(set), LOWER('Contact_Test__c')))}" /> -->
</apex:repeat>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
<script type="text/javascript">
try
{
var form = document.getElementsByTagName("FORM");
var formid= '#' + form[0].id.replace(/:/g, "\\:");
alert(formid);
$(formid+"\\:AccountBlock\\:AccountSection\\:Contact").val('{!$User.FirstName} {!$User.LastName}');
alert($(formid+"\\:AccountBlock\\:AccountSection\\:Contact").val('{!$User.FirstName} {!$User.LastName}'));
}
catch(err)
{
alert(err);
}
</script>

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

DannyK89DannyK89

I am having trouble using this 

$(formid+"\\:AccountBlock\\:AccountSection\\:Contact").val('{!$User.FirstName} {!$User.LastName}');

 with the value in the repeat tag. If it is used with something outside the repeat tag it works but I need it to work with a value inside the repeat tag. I was wondering if I can use the above code with the inputfield tag that has the Id ContactLookup.