<commit_before><script type="text/javascript">

    // The originally defined onSubmit function
    // We replace this with "return false;" until all errors are fixed
    var origOnSubmit = null;

    // to know if we have overwritten the onsubmit method already
    var overwrittenOnSubmit = false;
    
    /**
     * Validate the input format according to the regular expression.
     * If not valid, the background is highlighted and a formatting Hint is displayed.
     *
     * @param obj the input dom object
     * @param regex regular expression defined in the localized AddressTemplate in openmrs-servlet.xml
     * @param codeName the token.codeName (e.g.: "latitude")     
     */
    function validateFormat(obj, regex, codeName) {
        var formatMsg = "formatMsg_" + codeName;
        var resultArray = obj.value.match(regex);
        var tips = document.getElementsByName(formatMsg);
        if (resultArray || obj.value == null || obj.value == "") {
            obj.style.background="";
            for (var i=0; i<tips.length; i++) {
                tips[i].style.display = "none";
            }
            if (overwrittenOnSubmit) {
            	// replace the parent form's onsubmit with the one
            	// we saved because we put in a temporary "return false" in the onsubmit
            	obj.form.onsubmit = origOnSubmit;
            	origOnSubmit = null;
        		overwrittenOnSubmit = false;
            }
        }
        else {
            obj.style.background="yellow";
            for (var i=0; i<tips.length; i++) {
                tips[i].style.display = "";
            }

            if (!overwrittenOnSubmit) {
        		// this is the first time there was an error, save the current
        		// onSubmit for the form and replace it with a popup error msg
        		origOnSubmit = obj.form.onsubmit;
        		obj.form.onsubmit = function() { alert('${ ui.message("fix.error.plain") }'); return false; };
        		overwrittenOnSubmit = true;
        	}
        }
        
    }
    
</script>
    
<%
    config.require("addressTemplate")

    def addressTemplate = config.addressTemplate;
%>

<% addressTemplate.lines.each { line -> %>
        <% line.eachWithIndex { token, tokenIndex -> %>
            <% if (token.isToken == addressTemplate.layoutToken) { %>
            	 <p <% if (line.size() > 1 && tokenIndex == 1) { %> class="left clear" <% } else if (line.size() > 1) { %> class="left" <% } %> >
					<label name="${ token.codeName }">
	        			${ ui.message(token.displayText) }
	        		</label>
	        		
        			<input type="text" id="${ token.codeName }" name="${ token.codeName }" value="${ (addressTemplate.elementDefaults && addressTemplate.elementDefaults.get(token.codeName)) ? addressTemplate.elementDefaults.get(token.codeName) : '' }" size="${ token.displaySize }"
        			<% if (token.codeName == 'startDate' || token.codeName == 'endDate') { %> onfocus='showCalendar(this,60)' <% } %>
        			<% if (addressTemplate.elementRegex && addressTemplate.elementRegex[token.codeName]) { %> onkeyup="validateFormat(this, '${addressTemplate.elementRegex[token.codeName]}','${token.codeName}' )" <% } %>
        			/>
        			
        			<% if (addressTemplate.elementRegexFormats && addressTemplate.elementRegex[token.codeName]) { %>
	        			<i name="formatMsg_${token.codeName}" style="font-weight: normal; font-size: xx-small; color: red; display: none">
                                 <% if (addressTemplate.elementRegexFormats[token.codeName]) { %>
                                    (${ ui.message("general.format") }: ${addressTemplate.elementRegexFormats[token.codeName]})
                                <% } else { %>
                                    ${ ui.message("general.invalid") }&nbsp;${ ui.message("general.format") }
                                <% } %>
                        </i>
                    <% } %>
	        	</p> 
            <% } %>
        <% } %>
<% } %>
<commit_msg>Updated personAddress field to accept initial field values - RA-86<commit_after><script type="text/javascript">

    // The originally defined onSubmit function
    // We replace this with "return false;" until all errors are fixed
    var origOnSubmit = null;

    // to know if we have overwritten the onsubmit method already
    var overwrittenOnSubmit = false;
    
    /**
     * Validate the input format according to the regular expression.
     * If not valid, the background is highlighted and a formatting Hint is displayed.
     *
     * @param obj the input dom object
     * @param regex regular expression defined in the localized AddressTemplate in openmrs-servlet.xml
     * @param codeName the token.codeName (e.g.: "latitude")     
     */
    function validateFormat(obj, regex, codeName) {
        var formatMsg = "formatMsg_" + codeName;
        var resultArray = obj.value.match(regex);
        var tips = document.getElementsByName(formatMsg);
        if (resultArray || obj.value == null || obj.value == "") {
            obj.style.background="";
            for (var i=0; i<tips.length; i++) {
                tips[i].style.display = "none";
            }
            if (overwrittenOnSubmit) {
            	// replace the parent form's onsubmit with the one
            	// we saved because we put in a temporary "return false" in the onsubmit
            	obj.form.onsubmit = origOnSubmit;
            	origOnSubmit = null;
        		overwrittenOnSubmit = false;
            }
        }
        else {
            obj.style.background="yellow";
            for (var i=0; i<tips.length; i++) {
                tips[i].style.display = "";
            }

            if (!overwrittenOnSubmit) {
        		// this is the first time there was an error, save the current
        		// onSubmit for the form and replace it with a popup error msg
        		origOnSubmit = obj.form.onsubmit;
        		obj.form.onsubmit = function() { alert('${ ui.message("fix.error.plain") }'); return false; };
        		overwrittenOnSubmit = true;
        	}
        }
        
    }
    
</script>
    
<%
    config.require("addressTemplate")

    def addressTemplate = config.addressTemplate;
%>

<% addressTemplate.lines.each { line -> %>
        <% line.eachWithIndex { token, tokenIndex -> %>
            <% if (token.isToken == addressTemplate.layoutToken) { %>
            	 <p <% if (line.size() > 1 && tokenIndex == 1) { %> class="left clear" <% } else if (line.size() > 1) { %> class="left" <% } %> >
					<label name="${ token.codeName }">
	        			${ ui.message(token.displayText) }
	        		</label>
	        		<%
                    def initialFieldValue
                    if(config.initialValue && config.initialValue[token.codeName])
                        initialFieldValue = config.initialValue[token.codeName]
                    else
                        initialFieldValue = (addressTemplate.elementDefaults && addressTemplate.elementDefaults.get(token.codeName)) ? addressTemplate.elementDefaults.get(token.codeName) : ''
	        		%>
        			<input type="text" id="${ token.codeName }" name="${ token.codeName }" value="${(initialFieldValue) ? initialFieldValue : ''}" size="${ token.displaySize }"
        			<% if (token.codeName == 'startDate' || token.codeName == 'endDate') { %> onfocus='showCalendar(this,60)' <% } %>
        			<% if (addressTemplate.elementRegex && addressTemplate.elementRegex[token.codeName]) { %> onkeyup="validateFormat(this, '${addressTemplate.elementRegex[token.codeName]}','${token.codeName}' )" <% } %>
        			/>

        			<% if (addressTemplate.elementRegexFormats && addressTemplate.elementRegex[token.codeName]) { %>
	        			<i name="formatMsg_${token.codeName}" style="font-weight: normal; font-size: xx-small; color: red; display: none">
                                 <% if (addressTemplate.elementRegexFormats[token.codeName]) { %>
                                    (${ ui.message("general.format") }: ${addressTemplate.elementRegexFormats[token.codeName]})
                                <% } else { %>
                                    ${ ui.message("general.invalid") }&nbsp;${ ui.message("general.format") }
                                <% } %>
                        </i>
                    <% } %>
	        	</p> 
            <% } %>
        <% } %>
<% } %>

{'fraction_non_alphanumeric': 0.1340748714268628, 'fraction_numerical': 0.0019136466929793087, 'mean_word_length': 2.0035919540229883, 'pattern_counts': {'":': 0, '<': 64, '<?xml version=': 0, '>': 68, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1688438', 'n_tokens_mistral': 2411, 'n_tokens_neox': 2253, 'n_words': 529}