<commit_before>
exports.$directive = [
	'$compile', '$injector', '$q', 'form', 'require'
	($compile, $injector, $q, form, require) ->
		
		link: (scope, element, attrs) ->
			
			formKey = attrs['form']
			return unless (formSpec = scope[formKey])?
			
			# Hacking out the scope, gotta be a nicer way to do this.
			$form = angular.element '<form>'
			
			# Create the form element.
			$form = angular.element(
				'<form>'
			).attr(
				
				# Set submit handler, if any
				'data-ng-submit': "#{formKey}.submit.handler()"
				
				# Default method to POST.
				method: $form.attr('method') ? 'POST'
			
			).addClass formKey
			
			# Build the form fields.
			for name, field of formSpec
				continue unless field.type?
				
				$wrapper = angular.element '<div class="form-group">'
				$wrapper.append $field = switch field.type
					
					when 'email', 'password', 'text'
						$wrapper.append(
							angular.element('<label>').text field.label
						) if field.label?
						
						$input = angular.element(
							'<input type="' + field.type + '">'
						).attr(
							name: name
							'data-ng-model': name
						).addClass(
							'form-control'
						)
						
						if field.defaultValue?
							$input.attr 'value', field.defaultValue
						
						$input.attr 'required', 'required' if field.required
						
						$input
						
					when 'submit'
					
						if field.rpc?
							field.handler ?= ->
							handler = field.handler<commit_msg>Add hidden form field support to form API<commit_after>
exports.$directive = [
	'$compile', '$injector', '$q', 'form', 'require'
	($compile, $injector, $q, form, require) ->
		
		link: (scope, element, attrs) ->
			
			formKey = attrs['form']
			return unless (formSpec = scope[formKey])?
			
			# Hacking out the scope, gotta be a nicer way to do this.
			$form = angular.element '<form>'
			
			# Create the form element.
			$form = angular.element(
				'<form>'
			).attr(
				
				# Set submit handler, if any
				'data-ng-submit': "#{formKey}.submit.handler()"
				
				# Default method to POST.
				method: $form.attr('method') ? 'POST'
			
			).addClass formKey
			
			# Build the form fields.
			for name, field of formSpec
				continue unless field.type?
				
				$wrapper = angular.element '<div class="form-group">'
				$wrapper.append $field = switch field.type
					
					when 'hidden'
						
						scope[name] = field.value
						
						angular.element(
							'<input type="hidden">'
						).attr(
							name: name
						)
						
					when 'email', 'password', 'text'
						$wrapper.append(
							angular.element('<label>').text field.label
						) if field.label?
						
						$input = angular.element(
							'<input type="' + field.type + '">'
						).attr(
							name: name
							'data-ng-model': name
						).addClass(
							'form-control'
						)
						
						if field.defaultValue?
							$input.attr 'value', field.defaultValue
						
						$input.attr 'required', 'required' if field.required
						
						$input
						
					when 'submit'
					
						if field.rpc?
							field.handler ?= ->
							handler = field.handler
{'fraction_non_alphanumeric': 0.14157014157014158, 'fraction_numerical': 0.0, 'mean_word_length': 2.069101678183613, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6601079', 'n_tokens_mistral': 1432, 'n_tokens_neox': 931, 'n_words': 258}